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