Hi, i am trying to write a program that produces an out put that looks like the fallowing, using "printf()" and "scanf()"
Code:
X X^2 X^3
2.0e+000 4.00e+000 8.00e+000
3.0e+000 9.00e+000 2.70e+001
4.0e+000 1.60e+001 6.40e+001
5.0e+000 2.50e+001 1.25e+002
6.0e+000 3.60e+001 2.16e+002
7.0e+000 4.90e+001 3.43e+002
8.0e+000 6.40e+001 5.12e+002
9.0e+000 8.10e+001 7.29e+002
but the output that i am getting is nothing like it...
Code:
X X^2 X^3
2.121996e-314 4.940656e-324 1.#QNAN0e+000
8.487983e-314 3.952525e-323 1.#QNAN0e+000
1.909796e-313 1.333977e-322 1.#QNAN0e+000
3.395193e-313 3.162020e-322 1.#QNAN0e+000
5.304989e-313 6.175821e-322 1.#QNAN0e+000
7.639185e-313 1.067182e-321 1.#QNAN0e+000
1.039778e-312 1.694645e-321 1.#QNAN0e+000
1.358077e-312 2.529616e-321 1.#QNAN0e+000
1.718817e-312 3.601739e-321 1.#QNAN0e+000
my best guess is that the data i am trying to produce are exponential numbers (& the second column is the first one squared, and the third column is cubed) so i used the fallowing code... but i cant understand why it isn't working... please help
Code:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {
// Declare varaibles
float tbStart, tbEnd;
// Prompt for input
// First Number
printf("Please enter the first number for the table: ");
scanf("%e", &tbStart);
// Last Number
printf("Please enter the last number for the table: ");
scanf("%e", &tbEnd);
// print table header
printf("---------------------------------------------------------\n");
printf("Table of infomation\n\n");
printf("---------------------------------------------------------\n");
// print table information
printf("X X^2 X^3\n");
for (int i=tbStart; i<=tbEnd; i++) {
int sqr = i*i; int cub = i*i*i;
printf("%e\t\t%e\t\t%e\n",i,sqr,cub);
}
// print table footer
printf("---------------------------------------------------------\n");
scanf("%f",&tbEnd);
// end of program
return 0;
}