Program to find out the sum of first n numbers

Here is the program to find out the sum of first n numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "conio.h"
#include "stdio.h"
 
void main()
{
  int i=0,num,sum=0;
clrscr();  printf("\nEnter a number : ");
  scanf("%d",&num);
  for(;i<num;i++)
  {
  sum=sum+i;
  }
  printf("\n The sum of numbers = %d",sum);
getch();
}

Output:

Enter a number : 15
 
 The sum of numbers = 105
Chitra
Chitra

Leave a Reply

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

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in