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