Thursday, 4 November 2021

C Program to find sum of N numbers

 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

google-site-verification: google18ae80885fc3d876.html