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.
Answer Posted / 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 View All Answers
What is the meaning of c in c language?
Why is c used in embedded systems?
how to write a c program to print list of fruits in alpabetical order?
What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?
What is array in c with example?
Where static variables are stored in c?
What is the difference between abs() and fabs() functions?
What is the use of a conditional inclusion statement in C?
the question is that what you have been doing all these periods (one year gap)
Why we use conio h in c?
What is the code for 3 questions and answer check in VisualBasic.Net?
How do c compilers work?
Which is better oop or procedural?
Explain can static variables be declared in a header file?
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions