Tuesday, April 7, 2015

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



#include <stdio.h>
#include <conio.h>
#include <math.h>
int sum (int);
void main()
{
int i,n,num[50],result=0;
clrscr();
printf("\n How many numbers:- ");
scanf("%d“,&n);
printf{“\n Input %d numbers:- ",n);
for(i=0;i<n;i++)
scanf("%d",&num[i]);
for(i=0;i<n;i++)
result=sum(num[i]);
printf(“\n Result = %1d",result);
getch();
}
int sum(int x)
{
static int z;
z=z+x;
return (z);
}

No comments:

Post a Comment