C Program to find sum of N numbers
Program:-
#include<stdio.h>
#include<conio.h>
int sum(int);
int main()
{
int num,s;
printf("enter value of n:");
scanf("%d",&num);
s = sum(num);
printf("sum of %d numbers = %d\n", num, s);
}
int sum(int num)
{
int i,sum=0;
for(i=0;i<=num;i++)
{
sum = sum + i;
}
return sum;
}
Output:
enter value of n: 5
sum of %d numbers =15
No comments:
Post a Comment