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

مساعدة في تصحيح برنامج ب c++

بدأه emmmon في 1 أبريل 2012 · 1 رد · 441 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم.أرجو الساعدة في تصحيح هذا البرنامج ...أسعدكم الله..

#include <iostream>

using namespace std;

void output(int height, int width, long int * matrix)

{

cout<<"__________________"<<endl;

long int (*matrix2)[width];

matrix2=(long int (*)[width]) matrix;

int row_temp;

int column_temp;

for (row_temp=0;row_temp<height;row_temp++) {

for (column_temp=0;column_temp<width;column_temp++) {

cout<<matrix2[row_temp][column_temp]<<" ";

}

cout<<endl;

}

}

void switch_rows(int row1, int row2, int width, long int * matrix)

{

long int (*matrix2)[width];

matrix2=(long int (*)[width]) matrix;

int temp;

int column_temp;

for (column_temp=0;column_temp<width;column_temp++) {

temp=matrix2[row1][column_temp];

matrix2[row1][column_temp]=matrix2[row2][column_temp];

matrix2[row2][column_temp]=temp;

}

}

void multiply_row(int row, long int multiple, int width, long int * matrix)

{

long int (*matrix2)[width];

matrix2=(long int (*)[width]) matrix;

int column_temp;

for (column_temp=0;column_temp<width;column_temp++) {

matrix2[row][column_temp]=matrix2[row][column_temp]*multiple;

}

}

void add_rows(int row1, int row2, int width, long int * matrix)

{

long int (*matrix2)[width];

matrix2=(long int (*)[width]) matrix;

int temp;

int column_temp;

for (column_temp=0;column_temp<width;column_temp++) {

matrix2[row1][column_temp]=matrix2[row1][column_temp]+matrix2[row2][column_temp];

}

}

void add_multiple_of_row(int row1, int row2, long int multiple, int width, long int * matrix)

{

long int (*matrix2)[width];

matrix2=(long int (*)[width]) matrix;

int temp;

int column_temp;

for (column_temp=0;column_temp<width;column_temp++) {

matrix2[row1][column_temp]=matrix2[row1][column_temp]+(matrix2[row2][column_temp]*multiple);

}

}

int reduce_column(int column, int block_rows_until, int height, int width, long int * matrix)

{

long int (*matrix2)[width];

matrix2=(long int (*)[width]) matrix;

int row_temp;

int column_temp;

int temp;

int selected_row=-1;

for (row_temp=(height-1);row_temp>=block_rows_until;row_temp--) {

if (matrix2[row_temp][column]!=0) {

selected_row=row_temp;

}

}

if (selected_row==-1) {

return block_rows_until;

}

switch_rows(block_rows_until, selected_row, width, matrix);

for (row_temp=block_rows_until+1;row_temp<height;row_temp++) {

if (matrix2[row_temp][column]!=0) {

output(height, width, matrix);

temp=matrix2[row_temp][column];

multiply_row(row_temp, matrix2[block_rows_until][column], width, matrix);

output(height, width, matrix);

add_multiple_of_row(row_temp, block_rows_until, -(temp), width, matrix);

}

}

block_rows_until++;

return block_rows_until;

}

int main()

{

int width;

int height;

cout<<"Height? ";

cin>>height;

cout<<"Width? ";

cin>>width;

cout<<"Enter in the matrix row by row with entries separated by space:"<<endl;

long int matrix[height][width];

int row_temp;

int column_temp;

for (row_temp=0;row_temp<height;row_temp++) {

for (column_temp=0;column_temp<width;column_temp++) {

cin>>matrix[row_temp][column_temp];

}

}

long int * matrix_transfer;

matrix_transfer=(long int *) matrix;

int current_row=0;

int current_column=0;

int solved=0;

while (solved!=1) {

current_row=reduce_column(current_column, current_row, height, width, matrix_transfer);

current_column++;

if (current_row==(height-1)) {solved=1;}

if (current_column==(width-1)) {solved=1;}

}

output(height, width, matrix_transfer);

return 0;

}

ساعدوني الله يخليكم أريد البرنامج غدا

#2

تسمح لى أخى ان انتقدك؟

البرنامج يعمل بشكل تام

يبدو انك لم تفهم كيفية عمل البرنامج

البرنامج يعمل بهذة الطريقة:

1-ادخال اﻻرتفاع وليكن 3

2- ادخال العرض وليكن 3

3- دخال الصف اﻻول 2 ثم مسافة ثم 3 ثم مسافة ثم 4 ثم مفتاح اﻻدخال

كرر هذا بعدد الصفوف أى 3 مرات

لقد جربت البرنامج واليك المخرجات:

Height? 3
Width? 3
Enter in the matrix row by row with entries separated by space:
2 3 4 
3 5 6
2 3 4
__________________
2 3 4 
3 5 6 
2 3 4 
__________________
2 3 4 
6 10 12 
2 3 4 
__________________
2 3 4 
0 1 0 
2 3 4 
__________________
2 3 4 
0 1 0 
4 6 8 
__________________
2 3 4 
0 1 0 
0 0 0 

RUN SUCCESSFUL (total time: 26s)

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

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