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
Can i use “int” data type to store the value 32768? Why?
Why is c still so popular?
Why does not c have an exponentiation operator?
What is extern storage class in c?
How do you view the path?
How can I read and write comma-delimited text?
What does printf does?
Write a program to use switch statement.
Why c is called a middle level language?
Explain how can you be sure that a program follows the ansi c standard?
What is %lu in c?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
What is the use of printf() and scanf() functions?
Why we use stdio h in c?
What are the two types of structure?