I'm doing an assignment for an Intro to C class and one of the problems assigned from the book requires me to:
-Write a program that prompts the user to enter three numbers
-Prints the three numbers vertically, first forward and then reversed.
Simple enough, my code for that is
Code:
#include <stdio.h>
int main()
{
// Local Declarations
int a, b, c;
// Statements
printf("Please enter three numbers: \n");
scanf("%d %d %d", &a, &b, &c);
printf("\n\nYour numbers forward: \n%d \n%d \n%d\n\n", a, b, c);
printf("Your numbers reversed: \n%d \n%d \n%d", c, b, a);
return 0;
}
and the output is what I thought was required...
Please enter three numbers:
7 77 777
Your numbers forward:
7
77
777
Your numbers reversed:
777
77
7
I look back at the HW requirements and it turns out for this particular problem, my professor wants me to write more stuff; "Declare the three numbers of type double. Format the output: xxx.xx (such as 200.99, 50.25, etc.)."
Don't really have any idea on what to do for this... I changed the int to double but my output gets really weird.
This is the new code (with int changed to double)
Code:
#include <stdio.h>
int main()
{
// Local Declarations
double a, b, c;
// Statements
printf("Please enter three numbers: \n");
scanf("%d %d %d", &a, &b, &c);
printf("\n\nYour numbers forward: \n%d \n%d \n%d\n\n", a, b, c);
printf("Your numbers reversed: \n%d \n%d \n%d", c, b, a);
return 0;
}
This is the output with said-new code
Please enter three numbers:
5 10 15
Your numbers forward:
5
4200358
10
Your numbers reversed:
15
1988563298
10
Some advice would be greatly appreciated :X