-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcalculator.cpp
101 lines (95 loc) · 1.67 KB
/
calculator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<iostream>
using namespace std;
void sum(int a, int b);
void square(int c);
void cube(int y);
void subtract(int c, int d);
void remainder(int m ,int n);
void divide(int a, int b);
void reverse(int n);
void factorial(int n);
int main()
{
int a,b,c,d;
int y;
int m, n;
sum(a,b);
subtract(c,d);
square(c);
cube(y);
remainder(m,n);
divide(a,b);
reverse(n);
factorial(n);
return 0;
}
void sum(int a, int b)
{
int sum = a+b;
cout << "sum is" << sum;
}
void square(int c)
{
int square = c*c;
cout << "square is" << square;
}
void cube(int y)
{
int cube = y*y*y;
cout << "cube is" << cube;
}
void subtract(int c, int d)
{
int subtract = c-d;
cout<<"ans is"<<subtract;
}
void remainder(int m ,int n)
{
int rem = m%n
cout<<"the remainder is "<<rem;
}
void divide(int a, int b)
{
cout << "\n\n Divide two numbers and print:\n";
cout << "----------------------------------\n";
int a;
int b;
int resdiv;
a=30;
b=10;
resdiv=a/b;
cout << " The quotient of "<< a << " and "<<b <<" is : "<< resdiv <<"\n\n" ;
return 0;
}
void reverse(int n)
{
int n, reverse = 0, remainder;
printf("Enter any number: ");
scanf("%d", &n);
while(n != 0)
{
remainder = n%10;
reverse = reverse*10 + remainder;
n /= 10;
}
printf("Reversed Number = %d", reverse);
return 0;
}
void factorial(int n)
{
int n, i, factorial;
factorial = 1;
printf("Enter an integer: ");
scanf("%d",&n);
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else
{
for(i=1; i<=n; ++i)
{
factorial *= i;
}
printf("Factorial of %d = %llu", n, factorial);
}
return 0;
}