there is some problem?? first seven terms add using for loop


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include<iostream>
using namespace std;
main()
{
	int i,j;
	float f,sum;
	sum=0;
	for(i=1;i<=7;i++)
	{
		f=1;
		for(j=1;j<=i;j++)
		f=f*j;
		sum=sum+f/i;
		cout<<sum;	
   }
}
Last edited on
I think this is what you meant to do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
 
using namespace std;

int main()
{
	int i,j;
	float f,sum;
	sum=0;
	for(i=1;i<=7;i++)
	{
		f=1;
		for(j=1;j<=i;j++)
		{
	    	f=f*j;
		    sum=sum+f/i;
		}
		cout<<sum;	
   }
}


You forgot to put int before main()

Also you forgot the curly brackets after you for loop on line 11, which makes said loop to only apply to the following line.

Hope this helps
Thank you very much...
Topic archived. No new replies allowed.