#include <stdio.h>
#include <stdlib.h>

int main()
{
 begin();

}
int begin()
{

 long int b,res1,res2,res3;
 int a,c,d,e,f,i;     
 printf("Enter first number: ");
 scanf("%d",&a);
 printf("Enter second number: ");
 scanf("%ld",&b);

 c=b%10;
 d=b%100-c;
 e=b/100;
 res1=a*c;
 res2=a*d;
 res3=a*e;
 f=a*b;
 printf("\n\n\n");
 printf("    %d\n",a);
 printf("x\n");
 printf("     %d\n",b);
 printf("________\n");

 printf("   %ld\n",res1);

 printf("+ %ld\n",res2);

 printf(" %ld\n",res3);
 printf("_______\n");
 printf("%d\n",f);

 system("PAUSE");
 return 0;
}

hi i need to do the calculator above,code works fine,nothing special and very simple,but where were ger the subresult in res1,res2 and res3,is only for 3 multiple numbers,i need to do the printf with for loop ,so that would be flexible and printed as much numbers as it need no only 3.Can someone give some solutions/exaples ?Thank you.

Recommended Answers

All 4 Replies

I'm not sure I understand the requirements and they're not obvious from the code given. What should this calculator be doing?

i need to do print with for loop to be flexible,not res1,res2 and res3,it should miltiple in column,code work fine but i need to do printf with for loop

printf("   %d\n",res1);
 printf("+ %d\n",res2);
 printf(" %d\n",res3);

this part i should change to be flexible,with for loop

Ok, you've said the same thing three times now, but that's not what I want to know.

  • Why does that part need to be in a loop?
  • What is this program meant to accomplish?
  • What do res1, res2, and res3 represent?
  • Do you intend to have more than 3 results?
  • What are c, d, and e meant for?

Your code has no comments, you didn't post any assignment requirements, and didn't explain what the program actually does. Without knowing all of these things, there's really no way I can help you add a loop, because I have no idea what the loop is supposed to do.

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.