Computer Science, asked by Anonymous, 1 year ago

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
Anonymous: nepal
Anonymous: i am from Punjab
Anonymous: oooo
Anonymous: so we chat in other sites
Anonymous: what?
Anonymous: No....
Anonymous: why
Anonymous: i am busy sorry

Answers

Answered by ritvin3
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;

}


Anonymous: By go to statement
Anonymous: Program
Answered by Anonymous
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;
}

Anonymous: hmm
Anonymous: ha
Anonymous: kya ha
Anonymous: thik h
Anonymous: me to thik hu
Anonymous: u say
Anonymous: ok
Anonymous: r u crazy
Anonymous: plz stop comments
Anonymous: ok
Similar questions