What more to do ...

closed account (1Ujz3TCk)
If i want to get the following output

5 25
6 36
7 49
8 64
9 81
10 100


and my code is


1
2
3
4
5
6
7
8
9
10
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr ();
int i,pow;
for(i=5;i<=10;i++)
pow=(i,2);
cout<<i<<endl;
getch();}
Post your questions only at one forum.

You should do your own homework. Some notes to point you in the right direction:
-the power of i is i*i, not i*2
-you dont do anything with the calculated power
-you probably forgot the "{}" in the for loop
Last edited on
This is how I did it:


#include<iostream.h>

int main()
{
int i,pow;
for(i=5;i<=10;i++)
{

pow = i * i;
cout<<i <<" " <<pow<<endl;

}
return 0;
}

Any questios let me know
Last edited on
also use #include<iostream> NOT #include<iostream.h>

The .h version is depreciated.
The maths.h header already has a pow method in it. Etc
1
2
3
int answer;
answer = pow(12, 2);
answer would = 144 etc;


or This is a quick make for using a pow yourself..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <float.h>
#include <math.h>
//Using "long double" as using the pow(v1, v2);

void ToThePowerOf(long double ldBase, long double ldPower)
{
	std::cout << "\n-----------Start Function----------" << std::endl;
	long double ldTemp = 0;
	const long double cBaseValue = ldBase;

	for(long double i = 1; i < ldPower; i++)			
	{													
		ldTemp = 0;	//Reset Temp Value					
		ldTemp = ldBase * cBaseValue; //Calculate temp	
		ldBase = ldTemp; //Give Base temps value		
														
		std::cout << i << " Loop In Power Of = " << ldBase << std::endl;
	}

	std::cout << "\nFinal Answer : " << ldBase << std::endl;
	std::cout << "------------End Function-----------" << std::endl;
}

int main()
{
	long double valueOne = 0, valueTwo = 0;
	std::cout << "Please enter a base value: "; 
	std::cin >> valueOne;
	while((valueOne <= 1) || (_isnan(valueOne))) //(System::Double::IsNaN(valueOne))
	{
		valueOne = 0;
		std::cout << "Please enter a number greater than 1: ";
		std::cin >> valueOne;
	}

	std::cout << "Please enter a value for it to be powerd to: "; 
	std::cin >> valueTwo;

	std::cout << "The Value of " << valueOne << " to the power of " << valueTwo << " is " << std::endl;
	ToThePowerOf(valueOne, valueTwo);
	std::cout << std::endl;

	//Using The Math Method pow(value,value)
	std::cout << "Using The POW Maths.h Method the answer is:  ";
	long double answer;
	//Calling the method from the maths.h
	answer = pow(valueOne, valueTwo);
	std::cout << answer << std::endl;
}

Topic archived. No new replies allowed.