C++ program to find sum of series 1 + 2 + 3 +……+ n

C++ program to find sum of series 1 + 2 + 3 +......+ n

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,n,sum=0;
cout<<“1+2+3+……+n”;
cout<<“nEnter the value of n:”;
cin>>n;

for(i=1;i<=n;++i)
sum+=i;
cout<<“nSum=”<<sum;
getch();
}

11 thoughts on “C++ program to find sum of series 1 + 2 + 3 +……+ n

  1. muskaan dhasmana

    program in c++ to find sum of series sum=1+(1+2)+(1+2+3)+……………..n

    Reply
    1. SULTAN SHERYAR

      #include
      #include

      void main()
      {
      int i,j,n,sum=0;
      clrscr();
      n=10;
      for(i=1;i<=n;i++)
      {
      for(j=1;j<=i;j++)
      {
      sum+=j;
      }
      }
      cout<<"Sum: "<<sum;
      getch();
      }

      Reply
  2. Gohar

    bhai may nay ek program solve karna hy jis may hum nay ye series banana 1+1/4+1/8+1/12+…1/100
    kay ap bata saktay ho kaisay maloom karni hy c++ may

    Reply
    1. Mujeeb Ijaz

      #include
      using namespace std;

      void main()
      {
      float num=0;
      for (float i=4; i<=100; i=i+4)
      {
      num=num+(1/i);
      }
      num=num+1;
      cout << num;

      system("pause");
      }

      Reply
  3. tanvir

    bro what is the program for this series

    1+1+2+1+2+3+1+2+3+4+…………..1+2+3+………+n

    Reply
    1. Ravi Mishra

      #include
      #include
      void main()
      {
      int i,j,n,sum=0;
      clrscr();
      cout<>n;
      for(i=1;i<=n;i++)
      {
      for(j=1;j<=i;j++)
      {
      sum+=j;
      if(j==n)
      {
      cout<<j;
      }
      else
      {
      cout<<j<<"+";
      }
      }
      }
      cout<<"\nTotal Sum="<<sum;
      getch();
      }

      Reply
  4. Messiah

    can you help me with
    #include
    #include

    using namespace std;

    int main(){
    int cek=1, x=1, coba;
    cin >> coba;

    while(x <= coba){
    if (x% 2 == 1){
    Cek++;
    }
    else{
    Cek+=2;
    }
    cout<< cek << endl;
    x++;
    }
    return 0;
    }
    if cek =5
    i need 1,2,4,7,8
    but my code still 2,4,5,7,8

    Reply
  5. Fateh Said

    Please can anyone solve the following two questions for me its really very difficult same as given questions through c++ …
    Sum=1-1/1!+2/2!-3/3!…..n/n!
    Sum=x-x^3/3!+x^5/5!-x^7/7!+….x^n/n!

    Reply

Leave a Reply

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