Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Friday 4 November 2016

ZA. Greatest Common Divisor (GCD)

Problem link Click here


Score: 1

CPU: 1s
Memory: 256MB

You will be given two positive integers A and B. You have to calculate the GCD of given numbers. 
Input
First you will be given a positive integer T (1< T < 100), the number of test case. Each test case will contain two positive numbers Aand B ( 0 < A , B < 100000)

Output
For each test case you have to print the GCD of A and B in different lines.

Sample

InputOutput
2 2 4 6 15 Solutin
#include<stdio.h>
int main()
{
    int x,y,m,i,d,j;
    scanf("%d",&d);
    for(j=1;j<=d;j++){
    scanf("%d%d",&x,&y);
    if(x>y)
         m=y;
    else
         m=x;

    for(i=m;i>=1;i--){
         if(x%i==0 && y%i==0){
             printf("%d\n",i) ;
             break;
         }
      }
    }
    return 0;
}
2 3

1 comment:

  1. x,y,m,i,d,j এগুলো কি বুঝাচ্ছে একটু ক্লিয়ার করে দিন

    ReplyDelete