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

write a program to remove duplicate from an ordered char array? in c

2 Answers  


what is the output of the program and explain why?? #include<stdio.h> void main ( ) { int k=4,j=0: switch (k) { case 3; j=300; case 4: j=400: case 5: j=500; } printf (ā€œ%d\nā€,j); }

14 Answers   Oracle,


Why is it usually a bad idea to use gets()? Suggest a workaround.

1 Answers  


create an SINGLE LINKED LISTS and reverse the data in the lists completely

3 Answers  


can we access one file to one directory?

1 Answers  






write a program for size of a data type without using sizeof() operator?

22 Answers   HCL, IBM,


How to write a code for implementing my own printf() and scanf().... Please hep me in this... I need a guidance... Can you give an coding for c... Please also explain about the header files used other than #include<stdio.h>...

0 Answers  


How many loops are there in c?

0 Answers  


write aprogram for There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.

1 Answers   iGate, Shashi, Source Bits, Subex,


Why is not a pointer null after calling free?

0 Answers  


When is a void pointer used?

0 Answers  


What is pointers in c?

0 Answers  


Categories