this program will simply illustrate the multiplication of two numbers without using "*".Now let us see how it is working.Example: if we want answer of 2*5 then instead of multiplying numbers we can write it as "2+2+2+2+2".This program also does same.I have created one function named multi.In that i have used for loop to do multiplication(Like above).
Program:
#include<stdio.h>
#include<conio.h>
long multi(long,long);
main()
{
long a,b,ans;
clrscr();
printf("\nEnter number 1: ");
scanf("%ld",&a);
printf("\nEnter number 2: ");
scanf("%ld",&b);
ans=multi(a,b);
printf("\nMultiplication is %ld",ans);
getch();
}
long multi(long x,long y)
{
long answer=0,t;
for(t=y;t>=1;t--)
{
answer=answer+x;
}
return answer;
}
output:
Program:
#include<stdio.h>
#include<conio.h>
long multi(long,long);
main()
{
long a,b,ans;
clrscr();
printf("\nEnter number 1: ");
scanf("%ld",&a);
printf("\nEnter number 2: ");
scanf("%ld",&b);
ans=multi(a,b);
printf("\nMultiplication is %ld",ans);
getch();
}
long multi(long x,long y)
{
long answer=0,t;
for(t=y;t>=1;t--)
{
answer=answer+x;
}
return answer;
}
output: