TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Add substract multiply divide modulus inverse
Ashish Srivastava
Apr 03
2016
Code
748
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#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
divide
inverse
modulus
multiply
substract