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


Please Help Members By Posting Answers For Below Questions

What is the meaning of c in c language?

593


Why is c used in embedded systems?

609


how to write a c program to print list of fruits in alpabetical order?

1786


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

901


What is array in c with example?

612






Where static variables are stored in c?

582


What is the difference between abs() and fabs() functions?

601


What is the use of a conditional inclusion statement in C?

598


the question is that what you have been doing all these periods (one year gap)

1615


Why we use conio h in c?

582


What is the code for 3 questions and answer check in VisualBasic.Net?

1687


How do c compilers work?

606


Which is better oop or procedural?

628


Explain can static variables be declared in a header file?

676


C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions

606