-
April 10th, 2010, 09:43 AM
#1
Problem with program
Hi! I want help about a problem that I can't understand what i should do!
I want to create a program in C that will take (from a user) three integer numbers: x, y and n, and then make the count: x/y and print the result with n decimal numerals (that gave the user before).
Has anyone an idea?
-
April 10th, 2010, 09:59 AM
#2
Re: Problem with program
Yes, a good start would to buy a book or find a good online resource for learning to program.
-
April 10th, 2010, 10:06 AM
#3
Re: Problem with program
Originally Posted by jimmys
Hi! I want help about a problem that I can't understand what i should do!
I want to create a program in C that will take (from a user) three integer numbers: x, y and n, and then make the count: x/y and print the result with n decimal numerals (that gave the user before).
Has anyone an idea?
Originally Posted by Skizmo
Yes, a good start would to buy a book or find a good online resource for learning to program.
i know programming well. i know how to make program that make and print the x/y result, but how it can refund n decimal numerals?? this is my question! skizmo i think that it is not very simple program, because i know well programming, but i have difficulties in this program.
-
April 10th, 2010, 10:19 AM
#4
Re: Problem with program
Originally Posted by jimmys
i know programming well. i know how to make program that make and print the x/y result, but how it can refund n decimal numerals?? this is my question! skizmo i think that it is not very simple program, because i know well programming, but i have difficulties in this program.
Your requirement isn't clear to me. What refund? What do you mean "decimal numerals"?
-
April 10th, 2010, 10:33 AM
#5
Re: Problem with program
Originally Posted by GCDEF
Your requirement isn't clear to me. What refund? What do you mean "decimal numerals"?
sorry my english is not very good. i want to make a program that if for example the user give the numbers x=5, y=7 and n=3, the program should make 5/8 and print the result: 0,714.
With other words the variable n is the number of numerals after the " , "
if n is 4, it should print 0,7142.
if n=5, it should print 0,71428.
etc.
The program should operate even if the user give a big number, for example n=3.000.
I tell again that the numbers that give the user are all integer.
-
April 10th, 2010, 10:34 AM
#6
Re: Problem with program
Originally Posted by jimmys
if for example the user give the numbers x=5, y=7 and n=3, the program should make 5/8 and print the result: 0,714.
sorry i would like to write 5/7.
-
April 10th, 2010, 10:35 AM
#7
Re: Problem with program
Since it's plain C I have no better idea than creating the format string in code:
Code:
char fmt[10];
sprintf( fmt, "%%.%df", n );
printf( fmt, x/y );
-
April 10th, 2010, 10:51 AM
#8
Re: Problem with program
C or C++ I dont have problem... I want simply to make this program.
Thanks SMA! I will try it...
-
April 13th, 2010, 03:35 AM
#9
Re: Problem with program
you can use the * formatting to handle the decimals with using printf()
printf( "%0.*f", n, x/y);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|