Write a C program to find the sum of ‘N’ natural numbers

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program to find the sum of ‘N’ natural numbers */

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

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

clrscr();

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);
}

/*—————————————-
Output
RUN1

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

RUN2

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

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Sample – Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the diagonals also..
  2. Sample – Program to find the sum of either of the diagonals of a 4 x 4 matrix.
  3. C program to find the biggest of three numbers
  4. Write a C program to find the simple interest , given principle,rate of interest and times
  5. Sample – Program to enter an integer and find out if it is even or odd.

Leave a Comment

Previous post:

Next post: