|
| ||||||||||
| Tags: gcd, gcd of numbers, greatest common divisor, print gcd, program of gcd, two numbers gcd |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Program to print GCD of given numbers
I need you help in writing a program in C or C++ programming language. Suppose we have a program while execution of the program code, if we pass the two integer number then the desired output should be the GCD(Greatest Common Divisor) of the given two numbers. Please provide the program code to print the GCD of the given number. Even hint also will works for me. Your help will be greatly appreciated. Last edited by Bhavesh_seth : 27-11-2009 at 07:56 AM. |
|
#2
| ||||
| ||||
| Re: Program to print GCD of given numbers
Hi friends, I have used the the concept of the "Goto" statement to find out GCD of the two given number. I think it will also easy for you to understand the "Goto" statement than complex "For" loop. Please study below program carefully: Quote:
|
|
#3
| ||||
| ||||
| Re: Program to print GCD of given numbers
Hi, You should use "While loop" to find out the GCD of the inputted numbers. For reference take the following example which will calculates the GCD of numbers "a1" and "a2". The condition "a1!=a2" from the "While loop" first check whether two variables are identical or not: Quote:
|
|
#4
| |||
| |||
| Re: Program to print GCD of given numbers
Dear friend, I get below program from one of the C programming book, and which will explain you the logic of finding GCD of the given number: Quote:
|
|
#5
| ||||
| ||||
| Re: Program to print GCD of given numbers
It is very easy for me to write the program for GCD of 2 numbers. As I have sound knowledge about the various looping. Take below code and try to run. This code may contains some syntax error as I haven't executed it. Quote:
|
|
#6
| |||
| |||
| Re: Program to print GCD of given numbers
#include<stdio.h> main() { int x,y,i; printf("\n enter two numbers:"); scanf("%d%d",&x,&y); for(i==x;i>=1;i--) { if(x%i==0&&y%%i==0) { printf("\n gcd of two numbers is %d",i); break; } } } |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Program to print GCD of given numbers" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C Program to print Combination of numbers | Prashobh Mallu | Software Development | 6 | 26-03-2010 09:21 PM |
| Need C program code to count numbers of negative & positive numbers | Sarfaraj Khan | Software Development | 5 | 16-01-2010 01:00 PM |
| C sharp program to print random numbers | Prashobh Mallu | Software Development | 5 | 12-01-2010 11:07 AM |
| Program to print odd and even numbers | roodiii | Software Development | 3 | 30-11-2009 01:13 PM |
| What is the program to swap two numbers? | Bharat89 | Software Development | 3 | 26-11-2009 08:37 AM |