//program to get sum of 'n' integers using function.
#include<stdio.h>
#include<conio.h>
void sum();
void main()
{
sum();
getch();
}
void sum()
{int k=1,n,sum=0;
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
{
sum=sum+k;
k++;
}
printf("sum=%d",sum);
}
#include<stdio.h>
#include<conio.h>
void sum();
void main()
{
sum();
getch();
}
void sum()
{int k=1,n,sum=0;
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
{
sum=sum+k;
k++;
}
printf("sum=%d",sum);
}
No comments:
Post a Comment