1. ## multiplication program

Hi there, I need to write a program that multiplies two numbers and provides the output as follows:

Code:
```     50
x43
--------
150
+2000
--------
2150```

input first number;
input second number;
multiply two numbers to get the product;

my question is, how should i go about displaying the output like that (such as the 150 and 2000)? My idea would be to use an array and move along the array and multiply each number individually and then out put it like that. Would there be any easier way of doing this?

2. I'm not entirely sure what you're asking - are you talking about the best way to do the alignment? Or are you not sure how to input and output numbers?

It's probably best if you just make and attempt to meet the minimum requirements of the problem yourself. Post your source code, and if there's a way to improve it we can point it out to you. If you get stuck at a certain spot while you're trying, post your problem and we'll help you with that.

3. Originally Posted by sean
I'm not entirely sure what you're asking - are you talking about the best way to do the alignment? Or are you not sure how to input and output numbers?

It's probably best if you just make and attempt to meet the minimum requirements of the problem yourself. Post your source code, and if there's a way to improve it we can point it out to you. If you get stuck at a certain spot while you're trying, post your problem and we'll help you with that.
Sorry for the vaugness, heres the code I have so far:

Code:
```#include<stdio.h>

int main()
{

printf("Enter the number 1 : ");
scanf(&num1);

printf("Enter the number 2 : ");
scanf(&num2);

//output
printf(%d\nX,num1);
printf(%d\n-----------,num2);
printf(xxxxxxxxxxxxxxxx);
printf(xxxxxxxxxxxxxxxx);
return 1;
}```
So at the output, i was wondering how i would get the:
--------
150
+2000
--------
included. I dont really have any idea on how to go about that. I hope this makes sense, sorry for the confusion =(

4. Look up printf, and pay attention to the format width specifiers.

Quzah.

5. Originally Posted by quzah
Look up printf, and pay attention to the format width specifiers.

Quzah.
Gotcha. Now the last thing im trying to figure out is how do I find the numbers themselves? How would I get the 3*50, then shift to the 4 and multiply that by 50 and add a 0? Would I have to use arrays to do that?

6. Originally Posted by wankel
Sorry for the vaugness, heres the code I have so far:

Code:
```#include<stdio.h>

int main()
{

printf("Enter the number 1 : ");
scanf("%d", &num1);

printf("Enter the number 2 : ");
scanf("%d", &num2);

//output
printf("\n-----------";
printf("\n  %6d". num1);
printf("\n+%6d", num2);
printf("\n==========");
num1 = getchar();
return 1;
}```
So at the output, i was wondering how i would get the:
--------
150
+2000
--------
included. I dont really have any idea on how to go about that. I hope this makes sense, sorry for the confusion =(
When you use scanf(), remember to include what data type you will be giving to it: integer(%d), char(%c), string(%s), etc.

When you use printf(), remember to include double quotation marks, and within those marks, include the type of data type you want it to print up: integer(%d), char(%c), string(%s), etc.

When you use scanf(), remember to include what data type you will be giving to it: integer(%d), char(%c), string(%s), etc.

When you use printf(), remember to include double quotation marks, and within those marks, include the type of data type you want it to print up: integer(%d), char(%c), string(%s), etc.

8. Originally Posted by wankel
So at the output, i was wondering how i would get the:
--------
150
+2000
--------
included. I dont really have any idea on how to go about that. I hope this makes sense, sorry for the confusion =(

Try using modulous division. This should allow you to seperate out the 3 from the 40. It might get a little convoluted over 99, though.

Any other ideas?

9. Originally Posted by System_159
Try using modulous division. This should allow you to seperate out the 3 from the 40. It might get a little convoluted over 99, though.

Any other ideas?
Thanks System_159! I used your modulus division idea and im getting somewhere. However, my output values are way off, I keep getting crazy high numbers that dont make any sense. Can anyone tell me what i missed?

Code:
```#include <stdio.h>

int main ()
{
int number1;
int number2;
int sum;
int product;
int removed;
int digit;

printf("Enter first number:");
scanf("%d", &number1);
printf("Enter second number:");
scanf("%d", &number2);

//keep looping while the multiplier still has numbers
while (removed != '\0')
{
removed = number2/10;
digit = removed % 10;
product = digit*number1;
sum += product;
}

//checks the output
printf("%d", removed);
printf("\n");
printf("%d", digit);
printf("\n");
printf("%d", product);
printf("\n");
printf("%d", sum);

return 0;
}```
for the removed and digit, I get a zero which I think should be right. For the product and sum, I get crazy high numbers. Did I make a silly mistake in there?

10. Originally Posted by wankel
Code:
`	product = digit*number1;`
What do you think this line does?

11. Originally Posted by tabstop
What do you think this line does?
Im hoping that it takes the singled out digit of the second number, multiplies it with the first number and stores it in "product". Im assuming thats not whats happening right now?

12. Originally Posted by wankel
Im hoping that it takes the singled out digit of the second number, multiplies it with the first number and stores it in "product". Im assuming thats not whats happening right now?
That's what happens. Maybe I misunderstood your original post, or your intent, but you're only getting *just* that number multiplied, and not the value. (I.e. if you were doing 37*24, you'd just get 3*24, not 30*24.)

Also, sum is uninitialized, so you're starting off with some random number between -2billion and 2billion.