C Program to Add First N Numbers

//WAP TO ADD ALL PROGRAMS UPTO N(1 + 2 + 3..........+N)

#include <stdio.h>
int main()
{
	int n,sum = 0,i;
	printf("Enter the number :--> ");
	scanf("%d", &n);

	for(i = 0 ;i <= n; i++)
	{
		sum = sum + i;
	}

	printf("The sum of the first %d numbers : %d",n, sum);

	return 0;
}

<< Previous | Next >>


  • C++ Program to Add First N Numbers
  • Java Program to Add First N Numbers
  • Python Program to Add First N Numbers