C program to Find Sum of all Numbers b/w 1 to n ?
Q:- Write a C program to Find Sum of all Numbers b/w 1 to n ?
Input
#include<stdio.h>
#include<conio.h>
main()
{
int num,i=1,s=0;
clrscr();
printf(“Enter a Limit of N=”);
scanf(“%d”,&num);
while(i<=num)
{
s=s+i;
i++;
}
printf(“Sum of all Natural Numbers =
%d”,s);
getch();
}
Output
Enter a
Limit of N = 5
Sum of all
Natural Numbers = 15
Comments
Post a Comment