Thursday

Write a program to find the sum of n integer numbers using function.

#include<stdio.h>
#include<conio.h>
int sum(int);
void main()
{
 int n,a;
  clrscr();
 printf("\nEnter how many numbers: ");
 scanf("%d",&n);
 a=sum(n);
 printf("\n Sum of %d numbers= %d",n,a);
 getch();
 }

int sum(int n)
{
 int i,s=0;
 for(i=1;i<=n;i++)
 s=s+i;
 return s;
}

No comments:

Post a Comment

Rahul-Notes