Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Add substract multiply divide modulus inverse
WhatsApp
Ashish Srivastava
Apr 03
2016
795
0
0
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void
scan(
double
*n1,
double
*n2);
void
print(
double
r);
void
add(
double
*no1,
double
*no2);
void
substract(
double
*no1,
double
*no2);
void
multiply(
double
*no1,
double
*no2);
void
divide(
double
*no1,
double
*no2);
void
modulus();
void
inverse();
void
main()
{
double
num1,num2;
double
expression;
clrscr();
printf(
"\t1\tFor addition.\n"
);
printf(
"\t2\tFor substraction.\n"
);
printf(
"\t3\tFor multiplication.\n"
);
printf(
"\t4\tFor division.\n"
);
printf(
"\t5\tFor modulus.\n"
);
printf(
"\t6\tFor inverse.\n"
);
printf(
"\t0\tFor Exit.\n\n\n"
);
printf(
"\tEnter your choice :\n"
);
scanf(
"%d"
,&expression);
switch
(expression)
{
case
1:
add(&num1,&num2);
break
;
case
2:
substract(&num1,&num2);
break
;
case
3:
multiply(&num1,&num2);
break
;
case
4:
divide(&num1,&num2);
break
;
case
5:
modulus();
break
;
case
6:
inverse();
break
;
case
0:
exit(0);
break
;
default
:
printf(
"\n\t\tWrong choice.\n"
);
break
;
}
getch();
}
void
scan(
double
*n1,
double
*n2)
{
printf(
"\n\t\tEnter first number : "
);
scanf(
"%f"
,n1);
printf(
"\n\t\tEnter second number : "
);
scanf(
"%f"
,n2);
}
void
add(
double
*no1,
double
*no2)
{
double
result;
scan(no1,no2);
result=*no1+*no2;
printf(
"Addition of above two nos is %f"
,result);
}
void
substract(
double
*no1,
double
*no2)
{
double
result;
scan(no1,no2);
if
(*no1>*no2)
result=*no1-*no2;
else
result=*no2-*no1;
printf(
"Substraction of above two nos is %f"
,result);
}
void
multiply(
double
*no1,
double
*no2)
{
double
result;
scan(no1,no2);
result=*no1**no2;
printf(
"Multiplication of above two nos is %f"
,result);
}
void
divide(
double
*no1,
double
*no2)
{
double
result;
scan(no1,no2);
if
(*no1>*no2)
result = *no1 / *no2;
else
result = *no2 / *no1;
printf(
"Division of above two nos is %f"
,result);
}
void
modulus()
{
double
result,no1,no2;
printf(
"\n\t\tEnter first number : "
);
scanf(
"%d"
,no1);
printf(
"\n\t\tEnter second number : "
);
scanf(
"%d"
,no2);
if
(no1>no2)
result=no1%no2;
else
result=no2%no1;
printf(
"Modulus of above two nos is %d"
,result);
}
void
inverse()
{
double
result,no1;
printf(
"Enter an integer number to find it's inverse : "
);
scanf(
"%d"
,no1);
result = 1/no1;
printf(
"Inverse of above no is %f"
,result);
}
Add
substract
multiply
divide
modulus
inverse
Up Next
Add substract multiply divide modulus inverse