tough c questionss solve it

May 16, 2009 at 23:26:59
Specs: Windows XP
Write a program in C to find the sum of the first 100 natural numbers .

Sum=1+2+3+…….100


See More: tough c questionss solve it

Report •


#1
May 18, 2009 at 10:40:41
#include <stdio.h>
int main() {
printf("5050\n");
}

Report •

#2
May 18, 2009 at 10:42:55
How about c#?

int count = 0;
for (int i=1; i<=100; i++) {
count += i;
}


Report •

#3
May 18, 2009 at 13:04:37
heh...

#include <stdio.h>

int main(void) {

   int n;

   printf("Enter n term: ");

   if((scanf("%d", &n)) == 1) {
      printf("The sum of %d is %d\n", n, (n * (n + 1)) / 2);
   }
   
   return (0);
}

______________________
My work in progress. I hate JS. :P


Report •

Related Solutions


Ask Question