Home » Software » Language » C Programming » Write a C program to find the sum of ‘N’ natural numbers

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



/* 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
——————————————*/

Print Friendly

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *

Scroll To Top