Answer to Question #54895 in C++ for Charles

Question #54895
How to make a for loop version of simulating multiplication using repeated addition? Using printf and scanf and only the header stdio.h?
1
Expert's answer
2015-09-23T10:26:17-0400
#include <stdio.h>

int main()
{
int a;
printf("Enter a:");
scanf("%d", &a);

int b;
printf("Enter b:");
scanf("%d", &b);

int result = 0;
for (size_t i = 0; i < a; i++)
{
result += b;
}
int res = 0;
for (size_t i = 0 ; i < a; i++, res+=b)
{

}
printf("Res: %d \n", res);
printf("Result: %d \n", result);
printf("Test: %d \n", a*b);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Charles
23.09.15, 20:38

Thanks this will help a lot

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS