Back To C User Defined Functions Index
//program to create two functions that prints sum of even numbers and odd numbers between two numbers a and b (a nd b are passed to functions as integer arguments ) #include
#include
void sumeven(int,int); void sumodd(int,int); void sumeven(int a,int b) { int sume=0; int i; for(i=a;i<=b;i++) { if(i%2==0) { sume=sume+i; } } printf("sum of even numbers between a and b is %d",sume); } void sumodd(int a,int b) { int sumo=0; int i; for(i=a;i<=b;i++) { if(i%2!=0) { sumo=sumo+i; } } printf("sum of odd numbers between a and b is %d",sumo); } void main() { int a,b; clrscr(); printf("enter value for a"); scanf("%d",&a); printf("enter value for b"); scanf("%d",&b); sumeven(a,b); sumodd(a,b); getch(); }