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

What are terms in math?

0 Answers  


WHAT IS HEADER?

8 Answers   ProKarma, TCS,


Write a Program to find whether the given number or string is palindrome.

0 Answers   InterGraph,


write a program to count the no of repaeted words in a line?

1 Answers  


Function shall sum members of given one-dimensional array. However, it should sum only members whose number of ones in the binary representation is higher than defined threshold (e.g. if the threshold is 4, number 255 will be counted and 15 will not) - The array length is arbitrary - output the results to the stdout

0 Answers   XYZ,


N O S I E R + A S T R A L ---------------- 7 2 5 6 1 3

3 Answers   Honeywell,


void main(int argc,char *argv[],char *env[]) { int i; for(i=1;i<argc;i++) printf("%s",env[i]); }

3 Answers  


Juxtapose the use of override with new. What is shadowing?

1 Answers  


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

0 Answers  


how to set Nth bit of a variable?

1 Answers  


How to write a code for reverse of string without using string functions?

0 Answers   TCS,


How do we make a global variable accessible across files? Explain the extern keyword?

0 Answers  


Categories