الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

إيجاد القاسم المشترك الأعظم Gcd بإستخدام Euclid's Alg

بدأه لورنسوا في 11 أغسطس 2009 · 5 رد · 4,315 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

مرحبا في عندي سؤال بدي ابرمجه بال c++

والي هو ايجاد القاسم المشترك الاكبر GCD

انا برمجته واشتغل معي

وهاي الكود

#include<iostream>
using namespace std;
int main()
{

int num1;
int num2;
int gcd;
int i;

cout<<"enter two numbers : ";
cin>>num1>>num2;

for(i=1; i<=num1;i++)

{
if (num1%i ==0 && num2%i==0)
gcd=i;
}

cout<<"\n gcd = "<<gcd<<endl;

return 0;

}

يعني سهل كتير بس بدي اعطيكم كود تاني علة نفس السؤال بس فيه عليه كمان اسئله بدي تساعدوني فيها

  • Write the following program and run it for x=120 and y=80.

 <DIV class=smallfont style="MARGIN-BOTTOM: 2px">#include <iostream>
int GCD(int x, int y);
using namespace std;
int main()
{
	int x,y;
	cout<<"enter x value :"; cin>>x;
	cout<<"enter y value :"; cin>>y;
	cout<<"the GCD for"<<x<<"and"<<y<<"is"<<GCD(x,y)<<endl;
	
	int test;
	cin>>test;
	return 1;
}

int GCD(int x, int y){
	while (y!=0){
		 int t=x%y;
		 x=y;
		 y=t;
	}
	return x;
}</DIV>

  • Modify the code to print out the number of steps taken in the while loop.
  • Write a new function (called GCD2) that implements the recursive version of Euclid's algorithm.
  • Modify your function GCD2 to print out the number of the recursive calls made.
  • Call the two functions for the same inputs x and y to verify that both gives similar answers.
  • repeat the runs for different x and y values

Tasks:

1)Hand in the function GCD as explained in step 2.

2)Hand in the function GCD2 as explained in step 3.

3)Hand in the function GCD2 as explained in step 4.

4)Show sample runs for steps 5 and 6 (screen shots).

#2

أرجوا المساعدة للضرورة القصوى

وشكرا لكم

#3

لاتضع سؤالك بهذه الطريقة.

اين التنسيق من يستطيع يقراء الكود بهذه الطريقة ثم ضع كل مطلوب ومحاولتك وسوف نساعدك في تصحيحة بإذن الله.

tvquran_6.gif

#4

السلام عليكم

إيجاد القاسم المشترك الأعظم gcd بإستخدام

Euclid's algorithm

بإستخدام داله عوديه recursion

موجوده فى هذا الكود

#include <iostream.h>
int GCD2(int a,int b)
{
	if(b==0) return a;
	else
		return GCD2(b,a%b);
}
int main ()
{
	cout<<GCD2(12,15)<<endl;
return 0;
}

سلام

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#5

بلييييييييييييييز بدي حل سؤال بلغة جافا علي امتحان ب 20 علامه وهي السؤال واللي بقدر يساعدنني يبعثلي اياه على ايميلي بليييييييييييز (hala_83990@yahoo.com)

Q1) Write a complete java applet program to get current x,y of mouse pressed event .Your program should allow the following tasks:

1- Draws a random shapes if the GCD of x,y values is prime number.

2- Shows a menu of all string functions to allow user to select one string and to enter the corresponding required arguments if and only if the LCD of x,y values is even .

3- Shows all prime factorization of x,y if x=y.

4- Exit if the GCD is not prime and LCD is not even.

Note: values of x,y should be shown over the status bar of the applet.

Hint:

GCD: product of all the primes that appear in each factorization using each prime the smallest number of times it appears in any of the factorization

108: 2*2*3*3*3

240: 2*2*2*2*3*5

#6

هذا برنامج إخواني مكتوب في الـ سي بلس بلس بشكل منسق للفائدة

#include<iostream.h>
#include<math.h>
int main()
{
int num1;
int num2;
int gcd;
int i;
cout<<"enter two numbers : ";
cin>>num1>>num2;
for(i=1; i<=num1;i++)
{
if (num1%i ==0 && num2%i==0)
gcd=i;
}
cout<<"\n gcd = "<<gcd<<endl;
return 0;
}

و هذا الخرج التنفيذي له من أجل 120 و 80

post-217808-12604780559629_thumb.gif

مواضيع مشابهة