সমস্যা
দুই ইন্টিজারের গ্রেটেস্ট কমন ডিভাইজার (GCD) এবং লিস্ট কমন মাল্টিপল (LCM) বের করার জন্য ইউক্লিড অ্যালগরিদম ইমপ্লিমেন্ট করা এবং রেজাল্ট আউটপুট করা।
সমাধান
GCD এবং LCM বের করার লজিক:
if(firstno*secondno!=0){ gcd=gcd_rec(firstno,secondno); printf("\nThe GCD of %d and %d is %d\n",firstno,secondno,gcd); printf("\nThe LCM of %d and %d is %d\n",firstno,secondno,(firstno*secondno)/gcd); }
কলড ফাংশন:
int gcd_rec(int x, int y){ if (y == 0) return x; return gcd_rec(y, x % y); }
প্রোগ্রাম
ইউক্লিড অ্যালগরিদম ব্যবহার করে GCD এবং LCM বের করার সি প্রোগ্রাম:
#include<stdio.h> int gcd_rec(int,int); void main(){ int firstno,secondno,gcd; printf("Enter the two no.s to find GCD and LCM:"); scanf("%d%d",&firstno,&secondno); if(firstno*secondno!=0){ gcd=gcd_rec(firstno,secondno); printf("\nThe GCD of %d and %d is %d\n",firstno,secondno,gcd); printf("\nThe LCM of %d and %d is %d\n",firstno,secondno,(firstno*secondno)/gcd); } else printf("One of the entered no. is zero:Quitting\n"); } /*Function for Euclid's Procedure*/ int gcd_rec(int x, int y){ if (y == 0) return x; return gcd_rec(y, x % y); }
আউটপুট
Enter the two no.s to find GCD and LCM:4 8 The GCD of 4 and 8 is 4 The LCM of 4 and 8 is 8