write a program to deter;ine the sum of first n natural numbers by using of for loop or go to statement in c programming .
Anonymous:
thanks
Answers
Answered by
2
#include <stdio.h>
int main()
{
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=1; i <= n; ++i)
{
sum += i; // sum = sum+i;
}
printf("Sum = %d",sum);
return 0;
}
Answered by
3
#include <stdio.h>
int main()
{
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=1; i <= n; ++i)
{
sum += i; // sum = sum+i;
}
printf("Sum = %d",sum);
return 0;
}
int main()
{
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=1; i <= n; ++i)
{
sum += i; // sum = sum+i;
}
printf("Sum = %d",sum);
return 0;
}
Similar questions
India Languages,
6 months ago
Hindi,
6 months ago
Computer Science,
1 year ago
Math,
1 year ago
Math,
1 year ago