لتقوم بكتابة برمجة حساب مساحة المثلث ,ستحتاج إلى ثلاث متغيرات , واحد لطول القاعدة l و الثاني للإرتفاع h و الثالث للمساحة area :;float area,l ,h ; "cout << "please enter the Length and height of the triangle ; cin>>l>>h ;area =0.5*l*h ;cout <<"the area of the triangle is "<< area
اولا يجب ان نعرف قانون مساحة المثلث=0.5×طول القاعدة×الارتفاع لذلك سنعرف متغير للطول واخر للارتفاع حيث يتم ادخالهم من قبل المستخدم وايضا متغير اخر لنخزن فيه قيمه المساحه للمثلث.
;double A,B ;double trianglearea ;"cout << "please enter the Length of the triangle; cin>> A ;"cout << "please enter the height of the triangle ; cin>> B ; 0.5*trianglearea =A*B ;cout <<"the area of the triangle is "<< trianglearea