rabbinur

by using c++ the series 1+3+5+----+n

Sep 9th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  void main()
  4.  {
  5.   int i, n, sum=0;
  6.    clrscr();
  7.    cout<<"1+3+5+------+n:"<<endl;
  8.    cout<<"Enter n integer:"<<endl;
  9.    cin>>n;
  10.  
  11.    for(i=1; i<=n; i=i+2)
  12.     {
  13.      cout<<i<<endl;
  14.      sum=sum+i;
  15.     }
  16.      cout<<"The sum of series="<<sum<<endl;
  17.      getch();
  18.  }
Advertisement
Add Comment
Please, Sign In to add comment