-->
Showing posts with label program to get sum of 'n' integers using function.. Show all posts
Showing posts with label program to get sum of 'n' integers using function.. Show all posts

program to get sum of 'n' integers using function.

//program to get sum of 'n' integers using function.
#include<stdio.h>
#include<conio.h>
void sum();
void main()
{

sum();
getch();
}
void sum()
{int k=1,n,sum=0;
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
   {
      sum=sum+k;
      k++;
   }
printf("sum=%d",sum);
}