-
Notifications
You must be signed in to change notification settings - Fork 0
/
CQ6.c
52 lines (45 loc) · 1.29 KB
/
CQ6.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
/*
Information and Communications Technology by Professor Mujibur Rahman
Chapter 5 - C Programming, Creative Sample Questions, Page 375 (July 2016 Edition)
CQ 6
Difficulty:
Mid echelon Basic
Topics Covered:
Declarations, User Input, Console Printing, Computer Arithmetics, Console Functions
Reference:
Find the GCD of M & N where M > N > 0, of course, M and N are keyboard inputs
(Ex. 51%15 = 6 -> 15%6 = 3 -> 6%3 = 0 So GCD is 3)
//A,B and C are not relevant
//D) From the function in the given stem, write a C program that checks
if the numbers taken through keyboard input are even or odd numbers
Solution:
1. Targets:
. Take two keyboard inputs
. Decrement i from N until it's divisible with both M and N
. print i
2. Respective functions:
.scanf
.for loop and arithmetic
.printf
*/
#include <stdio.h> //printf, scanf
#include <conio.h> //getch
int main(){
int M,N,i = 1;
printf("Enter M: ");
scanf("%d",&M);
printf("Enter M: ");
scanf("%d",&N);
if (M < N || N < 1){
printf("Error: M < N || N < 1");
return -1;
}
while(i != 0){
i = M%N;
M = N;
N = i;
}
printf("GCD is %d\n",M);
getch();
return 0;
}