hi frnds!!

i have d code for series
x^!+x^2+x^3+....x^m

with single loop only

//wap to find sum of series and print series also
//x+x^2+x^3+......x^n
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,x,count1;
int sum=0;
cout<<"enter a number";
cin>>x;
cout<<"enter nth term till which u want to compute";
cin>>n;
int count=1;
for(int i=1;i<=n;i++)
{
count=count*x;
cout<<count;
cout<<" "<<"+"<<" ";
sum+=count;
}
cout<<"sum of series is="<<sum;
getch();
}

so enjoy!!
nd give ur comments if u like it...

Where are the code tags???

>>clrscr();
non-standard function that is normally available only to Turbo C. If you are going to post code snippets that everyone might want to use then don't use non-standard functions like that one.

>>cout<<count;
>>cout<<" "<<"+"<<" ";

You can abbreviate that into a single statement: cout << count << " + "; >>getch();
Don't use that in c++ programs. use cin.get() . This is an old thread, but still relevant.

First void main is a big no no. main should return an int and only an int. Second <iostream.h> is depreciated and should not be used as well. You should use <iostream> . Lastly please use indentation in you code. It makes it much easier to read.

commented: Yes +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.