Functionality
Read 2 numbers
Print multiplication as in following example:
3333
1111
----
***3333
**3333
*3333
3333
----
3702963

Prepare following functions
Modulo division (you cannot use '%')
Mulitplication
Print a number with leading and "following" spaces

Please I need to do that in C language, I think the best way to do it is converting to a array the second string that you enter by keyboard, then we must multiplicathe that array one by one to have the partial multiplications. Finally we have to put it in the correct position (I don't know how to do it) and print the multiplication result at the end.

Thank you very much!

Recommended Answers

All 3 Replies

#include <cstdlib>
#include <iostream>
#include "conio.h"

using namespace std;

int main(int argc, char *argv[])
{

int num1=0,num2=0,res=0;
printf("Please, enter a number: ");
scanf("%d",&num1);
printf("\n By this other number: ");
scanf("%d",&num2);
for(int cont=0;cont<num2;cont++)
{
res=res+num1;
}
printf("The result is: %d \n",res);

system("PAUSE");
return EXIT_SUCCESS;
}

Well, since you mentioned array, you can try this:

int num2[10], num1;

/* Input num1 here */
.....

/* Multiplication part */
for(cont = i - 1, n = 0; cont >= 0; cont--, n++) {
    res = res + ( (num1 * num2[cont]) * pow(10, n) );
}

This is nothing but,
eg: 1234 * 22

  1234 
x   22 
--------   _
    88      |
   660      |==>  pow(10, n) is used for this i.e purpose, multiplication by powers of 10.
  4400      |
 22000     _|
--------
 27148
--------

So, basically, input one of the numbers into an array. (getchar() can be used as shown)

while ( (c = getchar()) != '\n') {
        num2[i++] = c - '0';
}

So, the elements are in the array. All that's left is the multiplication, which has been shown above.

Is this what you were looking for?

PS: Please use code-tags for posting code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.