-
Notifications
You must be signed in to change notification settings - Fork 0
/
MP11A.c
116 lines (105 loc) · 2.75 KB
/
MP11A.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
107
108
109
110
111
112
113
114
115
116
/*Programmer's Block
Program Name: MP1A
Developer and Date of Submission: Shaw Jie Yao, October 07, 2021
Description of the program: Finds the factors of the two inputted non-zero positive numbers and provides the GCF or LCM of those numbers which are displayed on a menu.
*/
#include <stdio.h>
int main(void)
{
unsigned long long int N1, n1, N2, n2, f1, f2, GCF, gcf, LCM;
char choice;
do {
printf("\n\nNumber Manipulation:");
printf("\nA.GCF");
printf("\nB.LCM");
printf("\nC.Exit");
printf("\nEnter your choice:");
scanf(" %c", &choice);
switch (choice)
{
case 'A':
case 'a':
printf("Enter the first number: ");
scanf("%llu", &N1);
printf("Enter the second number: ");
scanf("%llu", &N2);
if(N1 < 100000001 && N2 < 100000001)
{
n1 = N1, n2 = N2;
printf ("FACTORS of\n%llu: ", n1);
for (f1 = 1; f1 <= n1; f1++)
{
if(n1 % f1 == 0)
{
printf ("%llu", f1);
if (f1 != n1) printf(", ");
}
}
printf ("\n%llu: ", n2);
for (f2 = 1; f2 <= n2; f2++)
{
if(n2 % f2 == 0)
{
printf ("%llu", f2);
if (f2 != n2) printf(", ");
}
}
for (gcf = 1; gcf <= n1; gcf++)
{
if(N1 % gcf == 0 && N2 % gcf == 0)
{
GCF = gcf;
}
}
printf("\nGCF = %llu", GCF);
}
break;
case 'B':
case 'b':
printf("Enter the first number: ");
scanf("%llu", &N1);
printf("Enter the second number: ");
scanf("%llu", &N2);
if(N1 < 100000001 && N2 < 100000001)
{
n1 = N1, n2 = N2;
printf ("FACTORS of\n%llu: ", n1);
for (f1 = 1; f1 <= n1; f1++)
{
if(n1 % f1 == 0)
{
printf ("%llu", f1);
if (f1 != n1) printf(", ");
}
}
printf ("\n%llu: ", n2);
for (f2 = 1; f2 <= n2; f2++)
{
if(n2 % f2 == 0)
{
printf ("%llu", f2);
if (f2 != n2) printf(", ");
}
}
for (gcf = 1; gcf <= n1; gcf++)
{
if(N1 % gcf == 0 && N2 % gcf == 0)
{
GCF = gcf;
}
}
LCM = (N1 * N2) / GCF;
printf("\nLCM = %llu", LCM);
}
break;
case 'C':
case 'c':
printf("\nThank You for using Number Manipulation!");
break;
default:
printf("\nEnter Valid Choice (A, B, C) only");
}
}
while (choice != 'C' && choice != 'c');
return 0;
}