GCD represents the greatest common divisor of two or more integers, excluding 0
For example, to find the greatest common divisor of 48 and 180
48 = 2 × 2 × 2 × 2 × 3
180 = 2 × 2 × 3 × 3 × 5
Greatest common divisor = 2 × 2 × 3 = 12.
In the given problem, N lines should be printed where the elements have the specified greatest common divisor
Input : N=2 GCD=2 Ouput : 2-4-6-10 14-16-18-22
START Step 1 -> take input n(e.g. 2) and k(e.g. 2) as int values and i Step 2-> Loop For i to 0 and i<n and i++ Print (k * (6 * i + 1)) Print (k * (6 * i + 2)) Print (k * (6 * i +3)) Print (k * (6 * i + 5)) Print </p><p> Step 3 -> end loop STOP
#include<stdio.h> int main() { int i,n = 2, k = 2; for (i = 0; i < n; i++) { printf("%d-",(k * (6 * i + 1))); printf("%d-",(k * (6 * i + 2))); printf("%d-",(k * (6 * i + 3))); printf("%d",(k * (6 * i + 5))); printf("</p><p>"); } return 0; }
If we run the above program, it will generate the following output.
2-4-6-10 14-16-18-22
The above is the detailed content of Print N rows of numbers so that the greatest common divisor between each pair of numbers is K. For more information, please follow other related articles on the PHP Chinese website!