Write a C++ program to sum of even numbes between 1 to 'n' terms using UDF(User Defined Functions).Turbo C++ 3.0 compatible. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Write a C++ program to sum of even numbes between 1 to 'n' terms using UDF(User Defined Functions).Turbo C++ 3.0 compatible.

n term will be input value

26th Dec 2017, 1:23 PM
Koustub Poddar
Koustub Poddar - avatar
5 Answers
+ 6
int main() { int n; int sum=0; cin>>n; for(int i=2;i<=n;i+=2) sum+=i; cout<<sum; return 0; }
26th Dec 2017, 1:38 PM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
26th Dec 2017, 1:41 PM
Dick Tracy
Dick Tracy - avatar
+ 1
#include<iostream> using name space std; bool sum(int a){ if(a%2) return true; return false; } int main(){ int n,s=0; cin>>n; for(int i=1;i<=n;i++) if(sum(n)) s+=n; cout<<s; return 0; }
26th Dec 2017, 1:43 PM
Nermeen
Nermeen - avatar
0
md.nafis did u use udf??
26th Dec 2017, 1:40 PM
C Lover
0
@Nermeen you could change function name sum to isOddNum. Otherwise nice code.
26th Dec 2017, 1:52 PM
$ยข๐Žโ‚น๐”ญ!๐จ๐“
$ยข๐Žโ‚น๐”ญ!๐จ๐“ - avatar