/* To find the sum
of first n numbers */
#include<stdio.h>
#include<conio.h>
void
main()
{
int n,i,sum=0;
clrscr();
printf("\nEnter the value of n: ");
scanf("%d",&n);
/*
Using FOR statement */
for(i=1; i<=n; i++)
{
sum=sum+i;
}
printf("\nSum of first %d numbers =
%d",n,sum);
getch();
}
OUTPUT
Enter
the value of n: 10
Sum
of first 10 numbers = 55
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.