C Programming Tutorial

Advertisements

Write program to show sum upto n numbers in c++



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

              cout<<"\nEnter any number : "; 
              cin>>num; 

              for(a=1;a<=num;a++)
                   sum = sum + a;
                                 
              cout<<"\nThe sum is : "<<sum; 

              getch();
       }
       
   Output : 

              Enter any number : 10 
              The sum is : 55




Advertisement