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
When should a far pointer be used?
What is difference between Structure and Unions?
How can you call a function, given its name as a string?
What 'lex' does?
a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor
Why flag is used in c?
What is a void pointer in c?
write a program fibonacci series and palindrome program in c
Describe the modifier in c?
What are header files in c?
Explain what is the most efficient way to store flag values?
What does struct node * mean?
Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me
What is the general form of a C program?
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?