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 does typedef struct mean?
Are pointers integers in c?
Explain bitwise shift operators?
What is include directive in c?
What is the most efficient way to count the number of bits which are set in an integer?
In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.
How can I determine whether a machines byte order is big-endian or little-endian?
What is the difference between the local variable and global variable in c?
Give me the code of in-order recursive and non-recursive.
Why dont c comments nest?
How can I read a binary data file properly?
What are the main characteristics of c language describe the structure of ac program?
Why do some versions of toupper act strangely if given an upper-case letter?
ATM machine and railway reservation class/object diagram
Explain how are portions of a program disabled in demo versions?