Friday, March 7, 2014

WRITE A FUNCTION TO CALCULATE SUM OF FIRST N INTEGERS

#include<conio.h>
#include<stdio.h>
void main()
{
void sum(int);
int n;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
sum(n);
getch();
}

void sum(int n)
{
int i,s=0;
for(i=0;i<=n;i++)
s=s+i;
printf("the sum of first %d nos is %d",n,s);
}

No comments:

Post a Comment