C program to find the sum of natural numbers from 1 to some maximum number n
Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will help us to calculate the sum of the numbers from 1 to some maximum number n which will be a natural number using the C program.
#include<stdio.h>
int main()
{
int num,i=1,sum=0;
printf("Enter the value of n:");
scanf("%d",&num);
while(i<=num)
{
sum=sum+i;
i++;
}
printf("The required sum is %d",sum);
}
Comments
Post a Comment