Like us on Facebook to get the latest links daily

Tuesday, December 20, 2011

C program to find the sum of 'N' natural numbers

/* Write a C program to find the sum of 'N' natural numbers*/

#include <stdio.h>
#include <conio.h>

void main()
    int i, N, sum = 0;


  printf("Enter an integer number\n");
scanf ("%d", &N);

    for (i=1; i <= N; i++)
      sum = sum + i;

printf ("Sum of first %d natural numbers = %d\n", N, sum);


Enter an integer number
Sum of first 10 natural numbers = 55


Enter an integer number
Sum of first 50 natural numbers = 1275

Get E-mail Subscription for Latest Updates

Don't forget to Click on activation link , sent to your E-mail ID

No comments:

Post a Comment

You might also like:

Related Posts Plugin for WordPress, Blogger...