Thursday 9 May 2013

Product of 2 numbers without using Arithmetic Operators



DESCRIPTION: This program finds the product of two numbers without using any of the arithmetic operators. Here we have made use of the looping methods to find the product of two numbers.


PROGRAM:


#include<stdio.h>
#include<stdlib.h>
void main()
{
    int n1,n2,temp=0,temp1,temp2;
    printf("Enter the 2 numbers\n");
    scanf("%d%d", &n1,&n2);
    if(n1==0&&n2==0)
    {
        printf("undefined\n");
        exit(EXIT_SUCCESS);
    }
    if(n1==0||n2==0)
  {
      printf("product=0\n");
      exit(EXIT_SUCCESS);
  }
    temp1=n1;
   temp2=n2;
    while(n1--)
   {
    while(n2--)
        temp++;
    n2=temp2;
   }
printf("%d*%d=%d",temp1,n2,temp);
}




OUTPUT WINDOW:


No comments:

Post a Comment