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

برنامج في الهوم وورك

بدأه N O R A في 1 أبريل 2012 · 9 رد · 808 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله

هذا سؤال في الهوم وورك وهذي صيغة السؤال:

Write a C++ program to calculate Sum, Average, Subtraction, Multiplication and Division of 2 numbers and 3 numbers.

محاولتي

# include<iostream.h>
int main()
{
double num1,num2,num3,sum1,sum2,average1,average2,sub1,sub2,mul1,mul2,div1,div2 ;
cout<<"enter the first number\n";
cin>>num1;
cout<<"enter the second number\n";
cin>>num2;
cout<<"enter the third number\n";
cin>>num3;
sum1=num1+num2;
sum2=num1+num2+ num3;
average1=(num1+num2)/2;
average1=(num1+num2+ num3)/3;
sub1=num1-num2;
sub1=num1-num2- num3;
mul1=num1*num2;
mul1=num1*num2*num3;
div1= num1/num2;
div1= num1/num2/num3;
cout<<"Subtraction of first two numbers"<<num1<<" and "<<num2<<" is :"<<sub1"<<endl;
cout<<"Subtraction of three numbers "<<num1<<" and "<<num2 <<" and "<< num3<<" is :"<<sub"<<endl;
cout<<"average1 of first two numbers "<<num1<<" and "<<num2 <<" is :"<< average1"<<endl;
cout<<"average1 of three numbers "<<num1<<" and "<<num2 <<" and "<< num3" is :"<< average1"<<endl;
cout<<"Multiplication of first two numbers "<<num1<<" and "<<num2 <<" is :"<<mul1"\n;
cout<<"Multiplication of the three numbers "<<num1<<" "<<num2<<" and "<< num3<<" is :"<<mul2"<<endl;
cout<<"Divition of first two numbers "<<num1<<" and "<<num2 <<" is :"<<div1"<<endl;
cout<<"Divition of three numbers "<<num1<<" and "<<num2 <<" and "<< num3" is :"<<div2"<<endl;

return 0;
}

فيه أخطاء بس ما عرفت مكان الخطأ بالضبط

#2

بعد التعديل :) ..

# include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
double num1,num2,num3,sum1,sum2,average1,average2,sub1,sub2,mul1,mul2,div1,div2 ;
cout<<"enter the first number\n";
cin>>num1;
cout<<"enter the second number\n";
cin>>num2;
cout<<"enter the third number\n";
cin>>num3;
sum1=num1+num2;
sum2=num1+num2+ num3;
average1=(num1+num2)/2;
average1=(num1+num2+ num3)/3;
sub1=num1-num2;
sub1=num1-num2- num3;
mul1=num1*num2;
mul1=num1*num2*num3;
div1= num1/num2;
div1= num1/num2/num3;
cout<<"Subtraction of first two numbers"<<num1<<" and "<<num2<<" is :"<<sub1<<endl;
cout<<"Subtraction of three numbers "<<num1<<" and "<<num2 <<" and "<< num3<<" is :"<<sub1<<endl;
cout<<"average1 of first two numbers "<<num1<<" and "<<num2 <<" is :"<< average1<<endl;
cout<<"average1 of three numbers "<<num1<<" and "<<num2 <<" and "<< num3<<" is :"<< average1<<endl;
cout<<"Multiplication of first two numbers "<<num1<<" and "<<num2 <<" is :"<<mul1<<"\n";
cout<<"Multiplication of the three numbers "<<num1<<" "<<num2<<" and "<< num3<<" is :"<<mul2<<endl;
cout<<"Divition of first two numbers "<<num1<<" and "<<num2 <<" is :"<<div1<<endl;
cout<<"Divition of three numbers "<<num1<<" and "<<num2 <<" and "<< num3<<" is :"<<div2<<endl;
getch();
return 0;
}
1
#3

شكراً أخوي :)

الله ينور لك ويسر لك أمورك يا كرييم ()()

طيب هذا بعد وين الخطأ ؟

int x, int y, int z, int& max, int& min)
{
     if (x<=y)
     {
          if (x<=z)
          {
               min=x;
               if (y<=z)
                    max=z;
               else
                    max=y;
          }
          else
          {
               min=z;
               max=y;
          }
     }
     else if (x<=z)
     {
          max=z;
          min=y;
     }
     else
     {
          max=x;
          if(y<=z)
               min=y;
          else
               min=z;
     }
}
#4

اش المطلوب من البرانامج الثاني ؟!

#5

هذا المطلوب الله ينور لك :

Write a C++ program to find the maximum and minimum of three numbers

إذا عندك طريقة أفضل غير طريقة الـ if & else أو أوضح من هذي ياليت طرحها ولك جزيل الشكر : )

#6
N O R A كتب:

هذا المطلوب الله ينور لك :

Write a C++ program to find the maximum and minimum of three numbers

إذا عندك طريقة أفضل غير طريقة الـ if & else أو أوضح من هذي ياليت طرحها ولك جزيل الشكر : )

أنظر الى: http://www.cplusplus.com/articles/S2zyhbRD/

1

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#7

^

^

مشكور اخوي :)

بس الأكواد المستخدمة ما بدينا فيها :"\

الي أخذناه السويتش كيس و اف ايلس و وايل ودو وايل

>>> تونا بالبداية يعنني ياليت الطرق السهلة :")

#8

لماذا تقومي بعمل الكود من خلال جمل ال if-else لكن بطريقة ابسط قليلا ، سانفذها ل max ونفسها تكون ل min

max=x;
if(y>max)max=y;else if(z>max) max=z;

نقطة اخرى : استخدام الاقترانات function يكون العمل بشكل عام افضل بحيث يكون ادخال الارقام وطباعة اكبر عدد واصغر عدد في ال main فقط والعمل والبحث كله في اقتران خاص

تم تعديل هذه المشاركة بواسطة يوسف حسين في 1 أبريل 2012 في 21:56

1
#9

عذرا .. لم الاحظ ان الكود الذي وضعه الاخ اوديونكس نفس فكرة الكود الذي وضعته .. لكن فكرته تقوم على اشياء تعلمتيها وهي جمل if else وهو بسيط وسلس جدا مقارنة بكودك... بالتوفيق

1
#10

شكراً لكم جميعاً ، وجزيتم الجنة لا حرمتم الأجر

تم كتابة البرنامج بطريقة الـ if :) ، وللإستفادة سأضعه هنا

#include <iostream.h>
void main()
{

	int a,b,c,max,min;
	cout<<"a= \n";
	cin>>a;
	cout<<"b= \n";
	cin>>b;
	cout<<"c= \n";
	cin>>c;
	max=a;
	min=a;
	if(max<b)
		if(max<c)
			max=b;
		max=c;
		cout<<"\n"<<max<<" is the max number\n";
		if(min>b)
			min=b;
		if(min>c)
			min=c;
		cout<<"\n"<<min<<" is the min number\n";
		}

: )

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