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

Why is structure important for a child?

0 Answers  


#include<stdio.h> void main() { int a=5,b=6,c; int x=(a<b)+7; int y=(x==7)*9; int z=(c=x+y)*2; printf("%h %h %h",x,y,z); } What is the output? Explain it.

8 Answers   IBM,


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

0 Answers  


What is the output of the program #include<stdio.h> #include<conio.h> void main() {0 int i,j=20; clrscr(); for(i=1;i<3;i++) { printf("%d,",i); continue; printf("%d",j); break; } getch(); }

4 Answers   CTS, Oracle,


how to swap two integers 1 and 32767 without using third variable

11 Answers   Microsoft, TCS,






Differentiate between null and void pointers.

0 Answers   TCS,


How do I get an accurate error status return from system on ms-dos?

0 Answers  


What is gets() function?

0 Answers  


printf("%d",(printf("Hello")); What it returns?

32 Answers   TCS,


How is a null pointer different from a dangling pointer?

0 Answers  


Is there any demerits of using pointer?

0 Answers  


Can a function argument have default value?

0 Answers   Genpact,


Categories