I need to line up my input. I am taking type double as my input how could I get the decimalsin line when I output them?
Thanks
I need to line up my input. I am taking type double as my input how could I get the decimalsin line when I output them?
Thanks
One more thing, is there another type that I can use besides double to get a greater precision(more decimal points)?
>>how could I get the decimalsin line when I output them?
do you mean printf format modifiers?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I know how to use printf but for example say you input vaules as
32.5
2.3
125.6
1110.3
I need to output them in the following format:
32.5
2.3
125.6
1110.3
where the decimals line up with one another.
Thanks
Use the code tags to keep the formating on these boards.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
printf("Enter a number...");
scanf("%lf" , &n);
[/code]
Need to out put as follows:
32.5
2.3
125.6
1110.3
Is that what you mean?
Do this
[code]
Need to out put as follows:
32.5
2.3
125.6
1110.3
[/code]
And you'll get
... so you can format the output correctly:Code:Need to out put as follows: 32.5 2.3 125.6 1110.3
Do this, and tell us what you want again.Code:Need to out put as follows: 32.5 2.3 125.6 1110.3
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I need to line up the input by their decimals.
Code:input as follows: 32.5 2.3 125.6 1110.3Code:Need to output as follows: 32.5 2.3 125.6 1110.3
Last edited by jwhitaker3; 09-09-2002 at 08:47 AM.
Try
printf("%8.1f\n", d);
> is there another type that I can use besides double to get a greater precision
There's long double, but it only adds a few decimal places
If you want more, then you need to resort to an external math package like
GMP
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
printf("%8.1f", n)
Only lets one decimal place be output.
Yes I have tried 8.3f and different values.
This only lines up the first digit
12.3
2.3
However I need it to be this.
Code:12.3 2.3
Code:#include <stdio.h> int main(void) { printf (">%8.3f<\n", 12.3); printf (">%8.3f<\n", 2.3); return 0; } /* Program output: > 12.300< > 2.300< */
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]