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 |