Function Main
Declare Integer A
Declare Integer B
Declare Integer res
Output "Insert 2 numbers to calculate GCD"
Output "First number: "
Input A
Output "Second number"
Input B
Assign res = GCD(a,b)
Output res
End
Function GCD (Integer a, Integer b)
Declare Integer res
If a = 0
Assign res = b
Else
Assign res = GCD(b MOD a, a)
End
Return Integer res
#include <stdio.h>
int GCD(int a, int b);
int main() {
int a;
int b;
int res;
printf("Insert 2 numbers to calculate GCD:\n");
printf("First number: \n");
scanf("%d", &a);
printf("Second number:\n");
scanf("%d", &b);
res = GCD(a, b);
printf("%d\n", res);
return 0;
}
int GCD(int a, int b) {
int res;
if (a == 0) {
res = b;
} else {
res = GCD(b % a, a);
}
return res;
}
I am Md. Anisur Rahman. I have completed Cyber Security for MSCSE at United International University in 2022.I have completed PGDIT from IIT, Jahangirnagar University in 2020. I'm a Head of IT at Programming24 School.
View all posts by Md. Anisur Rahman