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();
}

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

    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();
      }

  1. 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

    1. #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");
      }

    1. #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();
      }

  2. 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

  3. 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!

    1. Sum of the Series 1 – 1/1! – 2/2! + 3/3! – 4/4! + ……1/N!

      /* Program */
      #include
      using namespace std;

      double sumseries(double);

      main()
      {
      double number,sum;
      cout<>number;
      sum = sumseries(number);
      cout<<"\n Sum of the above series = "<<sum;
      }

      double sumseries(double m)
      {
      double sum2 = 0, f = 1, i;
      int count = 0;
      for (i = 1; i <= m; i++)
      {
      f = f * i;
      if(count%2!=0)
      sum2 = sum2 +(i / f);
      else
      sum2 = sum2 – (i/f);
      count++;
      }
      return(1-sum2);
      }

      1. Abhishruti Mandal

        Sum of the Series 1 – 1/1! + 2/2! – 3/3! + 4/4! – ……1/N!

        /*
        * C++ Program
        */
        #include
        using namespace std;

        double sumseries(double);

        main()
        {
        double number,sum;
        cout<>number;
        sum = sumseries(number);
        cout<<"\n Sum of the above series = "<<sum;
        }

        double sumseries(double m)
        {
        double sum2 = 0, f = 1, i;
        int count = 0;
        for (i = 1; i <= m; i++)
        {
        f = f * i;
        if(count%2!=0)
        sum2 = sum2 +(i / f);
        else
        sum2 = sum2 – (i/f);
        count++;
        }
        return(1-sum2);
        }

  4. a. Calculate the summation of the series: 1+2+3+4+… … … +20 (using loop)

    b. Calculate the area of the triangle. [Hints: area of triangle = 0.5 x base x height]

  5. 7. //Computes for the Summation of the series 1^1 + 2^2 + 3^3 + … + n^n…
    #include
    #include
    using namespace std;

    long long series (int n);
    int main()
    {
    int _____;
    cout <> n;
    for (int i = __1__; i<=n; i++)
    if (i<_____)
    cout << i << “^” << “+”;
    else
    cout << i << “^” << “–”;
    cout << _____ (n) << endl;
    system(“pause”);
    }
    _long_ series int(_____)
    {
    If (n==0)
    return(_____);
    else
    return pow(n,n) + series(_____);
    }

Leave a Comment

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