C program – Calculate the greatest Common Divisor (GCD) of a number

by Nideesh C on April 17, 2011 · 1 comment

in C Programming




#include<stdio.h>
#include<conio.h>
#include<process.h>
int gcd(int m,int n)
{
	int rem;
	while(n!=0)
	{
		rem=m%n;
		m=n;
		n=rem;
	}
	return(m);
}
main()
{
	int num1,num2,num3,gcd1,gcd2;
	clrscr();
	printf("Enter three positive integers");
	scanf("%d%d%d",&num1,&num2,&num3);
	if(num1==0 && num2==0 && num3==0)
	{
		printf("\n Invalid number");
		exit(0);
	}
	gcd1=gcd(num1,num2);
	gcd2=gcd(num3,gcd1);
	printf("\n GCD of %d %d %d is : %d\n",num1,num2,num3,gcd2);
	getch();
}



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to find the GCD and LCM of two integers output the results along with the given integers. Use Euclids’ algorithm
  2. Sample – Program to enter an integer and output it in the reversed form.
  3. C program to accept a decimal number and conert it binary and count the number of 1′s in the binary number
  4. Sample – Program to convert 2-digit octal number into binary number and print it.
  5. C program to convert the given binary number into decimal

{ 1 comment… read it below or add one }

1 shyavhioo May 20, 2011 at 11:14 pm

C program – Calculate the greatest Common Divisor (GCD) of a number is a good article

Reply

Leave a Comment

Previous post:

Next post: