+ 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
5 odpowiedzi
+ 6
int main() {
int n;
int sum=0;
cin>>n;
for(int i=2;i<=n;i+=2)
sum+=i;
cout<<sum;
return 0;
}
+ 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;
}
0
md.nafis did u use udf??
0
@Nermeen you could change function name sum to isOddNum. Otherwise nice code.