C Programming Tutorial

Advertisements

Write program to show sum upto n numbers in c



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
              int a,num,sum=0;

              printf("\nEnter any number : "); 
              scanf("%d",&num); 

              for(a=1;a<=num;a++)
                   sum = sum + a;
                                 
              printf("\nThe sum is : %d",sum); 

              getch();
       }
       
   Output : 

              Enter any number : 10 
              The sum is : 55




Advertisement