# Thread: need help with c programming hmwk

1. ## need help with c programming hmwk

Can someone please help me with this assignment? I'm a programming noob and any help would be greatly appreciated. Write a program that receives an integer from user and prints out the number of thousands,
hundreds, tens and ones in it. You need to specify the number of thousands, hundreds, tens and
ones, even if the number is larger than 9,999. [Hint: if a and b are two integers, then a/b is the
quotient obtained by dividing a by b and a%b is the remainder obtained by dividing a by b].

2. Well, there's a pretty good hint about divide and modulo in the description, so you may want to look into that.

Once you have written a bit of code, you can post it here, with any questions you have, but we don't do other peoples homework. Just like the discussion board for the English language may be able to help you form a sentence correctly, but they won't write your 500 word essay for you. [This program would be about 5-10 lines depending on how you do it, so it's much less than a 500 word essay.]

--
Mats

3. This is my program thus far:
{int a, b, thousands, hundreds, tens, ones;
b=1000;
printf("Enter a number: ");
scanf("%f", &a);
thousands= a/b;
printf("%d", thousands);
So I want to divide the integer by 1000 to get a number that is truncated leaving the correct amount of thousands. When I run this and enter an integer, i get garbage numbers. Is this the way I should go about this assignment? How can I employ the hint given to make this easier.

4. Nobody in the board would say that is a code. The code with no main and include's and most of all with no return. Perhaps the code tag. Here we go i will do it for you

Code:
```#include <stdio.h>
int main()
{
int a, b, thousands, hundreds, tens, ones;
b=1000;

printf("Enter a number: ");
scanf("&#37;f", &a);
thousands= a/b;
printf("%d", thousands);

getchar();
return 0;
}```
Now, from here you start. Look at basics of C, understand what you need to do at initial. Rob had given some good links have a look at it

ssharish2005

5. Originally Posted by nafix
This is my program thus far:
{int a, b, thousands, hundreds, tens, ones;
b=1000;
printf("Enter a number: ");
scanf("%f", &a);
thousands= a/b;
printf("%d", thousands);
So I want to divide the integer by 1000 to get a number that is truncated leaving the correct amount of thousands. When I run this and enter an integer, i get garbage numbers. Is this the way I should go about this assignment? How can I employ the hint given to make this easier.
%f is a "floating point" format for scanf - it reads in values like 2.5 or 1.9272937. If you enable warnings (at least on gcc), it should give you a warning when you compine an int inptu to scanf with a float or char format specifier.

--
Mats

6. [QUOTE=nafix;669551]This is my program thus far:
Code:
```#include <stdio.h>
int main(void)
{int a, b, thousands, hundreds, tens, ones;
b=1000;
printf("Enter a number(integer): ");
scanf("%d", &a);
thousands= a/b;
printf("%d", thousands);

return 0;
}```
So far, this gives me 4 for the thousands which is what I want. But I'm having trouble getting the hundreds, tens, and ones. And I can't think of a way to obtain the other decimal places. Can someone give me a nudge in the right direction?

7. minus the thousands (thousands * 1000) and then do the same thing for 100.

8. but the program has to work for integers over 9,999. subtracting out 1000 wouldn't work for things over that number, right?

9. Of course, there is a big hint in the original problem defintion. Try reading that again.

--
Mats

10. Is there a way to print out the remainder of integer/ 1000? So if i divide 12225 by 1000 to get 12.225, can I print out the 2 for hundreds, 2 for tens, and 5 for ones? Or can I print out the remainder next divided by 100 for hundreds, then print remainder divided by 10 for tens place and so on? How would I print out just the remainder.

11. num&#37;100

modulo

12. do i put that in a print function? how would i go about initializing modulo in code?

13. [QUOTE=nafix;669560][QUOTE=nafix;669551]This is my program thus far:
Code:
```#include <stdio.h>
int main(void)
{int a, b, c, thousands, hundreds, tens, ones;
b=1000;
printf("Enter a number(integer): ");
scanf("&#37;d", &a);
thousands= a/b;
printf("%d", thousands);
c= a%b
hundreds= c/100;
printf("%d Hundreds", hundreds);

return 0;
}```
This is my revised code, but now I'm printing out 0 for thousands and hundreds. WHat am I doing wrong?