-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCD Using for loop and if Statement.php
73 lines (61 loc) · 2.2 KB
/
GCD Using for loop and if Statement.php
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
<html>
<head>
<style> div.cd{background:teal;} a{text-decoration:none; color:white;} p{font-size:20;text-align:justify;} th:hover{background-color:black;} th{font-size: 20}
</style>
</head>
<body bgcolor="">
<div class="cd" style="color:white;font-size:50;width:100%;top:0;left:0;position:sticky;border: 1px solid black">
<table >
<tr> <td><img src="logo.png" width="100" height="100" style="padding-left:50" alt="loading.."></td>
<td> <font color="white" size="33" face="cooper" > Fast & Furious Logics </font> </td>
<form method="post" action="<?php $_PHP_SELF ?>">
<td align="right" style="padding-left:350;font-size:25">
<font color="white" face="cooper" > search <input type="text" name="search">
</font>
</td>
</form>
</tr>
</table>
</div>
<table >
<tr >
<td height="100%" valign="top">
<iframe src="links.php" height="520" style="overflow:scroll;top:0"></iframe>
</td>
<td valign="top" style="font-size: 20;font-family: cursive;" width="750">
<div style="overflow: scroll ; height:550;">
<h1>
GCD Using for loop and if Statement
</h1>
The HCF or GCD of two integers is the largest integer that can exactly
divide both numbers (without a remainder).There are many ways to find
the greatest common divisor in C programming.
<pre>
int main()
{
int n1, n2, i, gcd;
printf("Enter two integers: ");
scanf("%d %d", &n1, &n2);
for(i=1; i <= n1 && i <= n2; ++i)
{
// Checks if i is factor of both integers
if(n1%i==0 && n2%i==0)
gcd = i;
}
printf("G.C.D of %d and %d is %d", n1, n2, gcd);
return 0;
}
In this program, two integers entered by the user are stored in variable
n1 and n2.Then, for loop is iterated until i is less than n1 and n2.
</pre>
In each iteration, if both n1 and n2 are exactly divisible by i, the value of i is assigned to gcd.
When the for loop is completed, the greatest common divisor of two numbers is stored in variable gcd.
</div>
</td>
<td valign="top">
<iframe src="comment.php" height="520"></iframe>
</td>
</tr>
</table>
</body>
</html>