-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq3.c
109 lines (98 loc) · 1.63 KB
/
q3.c
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
102
103
104
105
106
#include <stdio.h>
void repeat();
int c,b,x,q;
int Largest_element(int *p,int l)
{
int a;
a=*(p+l-1);
if(l==1)
{
return a;
}
int b=Largest_element(p,l-1);
return a>b?a:b;
}
int gcd(int n1,int n2)
{
int a;
if(c==1)
{
b=1;
}
else
{
if(n1%c==0&&n2%c==0)
{
b=c;
}
}
if(c==n1||c==n2)
{
a=b;return a;
}
c++;
a=gcd(n1,n2);
return a;
}
int power(int n1,int n2)
{
if(x<=n2)
{
q=q*n1;
x++;
q=power(n1,n2);
}
return q;
}
int main()
{
int n,l;
c=1,x=1,q=1;
printf("Which case do you choose-Case ");
scanf("%d",&n);
if(n==1)
{
scanf("%d",&l);
int arr[l];
int i;
for(i=0;i<l;i++)
{
scanf("%d",&arr[i]);
}
int lg=Largest_element(arr,l);
printf("The largest element is %d",lg);
repeat();
}
else if(n==2)
{
int n1,n2;
scanf("%d %d",&n1,&n2);
int n=gcd(n1,n2);
printf("The GCD is %d",n);
repeat();
}
else if(n==3)
{
int n1,n2;
scanf("%d %d",&n1,&n2);
int p=power(n1,n2);
printf("The answer is %d",p);
repeat();
}
else
{
printf("Give a valid input");
main();
}
return 0;
}
void repeat()
{
int e;
printf("\nIf you want to run again-enter 0, if you want to quit-enter anything");
scanf("%d",&e);
if(e==0)
main();
else
return;
}