C Program to multiply two numbers without using * operator

Description

Get two inputs  num1 and num2, compute the product of num1 and num2 without using  * operator
Input:
5 6
Output:
30

Solution

#include<stdio.h>
int main()
{
	int num1,num2,product=0;
	printf("Enter two numbers:");
	scanf("%d %d",&num1,&num2);
	while(num2>0)
	{
		product=product+num1;
		num2--;
	}
	printf("The product is :%d",product);
	return 0;
}

Explanation

4*5 = 4+4+4+4+4

Add the 4 with product for 5 times using while statement.



Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution