write a program that will accept two integers and will implement division without using the division operator if the second value is an odd number and will implement multiplication without using multiplication operator if the second value is an even number.



write a program that will accept two integers and will implement division without using the division..

Answer / yogi patel

//Yogi patel
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,ans,i;
clrscr();
printf("Enter first number :->> ");
scanf("%d",&a);
printf("Enter second number :->> ");
scanf("%d",&b);

if(b%2==0)
{
ans=a;
printf("Division perform");
for(i=0; i<(a/2); i++)
{
ans=ans-1;
}
printf("\n\nAns is :- %d",ans);
}
else
{
ans=0;
printf("Multiplication perform");
for(i=0; i<b; i++)
{
ans=ans+a;
}
printf("\n\nAns is :- %d",ans);
}
getch();
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

how can i get output like this? 1 2 3 4 5 6

6 Answers   Excel,


Explain continue keyword in c

0 Answers  


What is preprocessor with example?

0 Answers  


How do I convert a string to all upper or lower case?

0 Answers  


Are there constructors in c?

0 Answers  






what is the difference between structure and union?

3 Answers  


Is there any restriction in how many arguments printf or scanf function can take? in which file in my c++ compiler i can see the code for implementation of these two functions??

4 Answers  


Can a function argument have default value?

0 Answers   Genpact,


12345 1234 123 12 1

2 Answers  


What is the value of h?

0 Answers  


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

0 Answers  


What is a buffer in c?

0 Answers  


Categories