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

كيف نعمل شرط لتوقف مصفوفه من لوووب

مغلق
بدأه sman93 في 7 مايو 2003 · 6 رد · 790 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام علكم ورحمه الله وركاته

المشكله التي اريد الحل لها هي تتلخص بالتالي:

انني اريد ان اعمل مصفوفه يكون عدد الصفوف وعدد الاعمده

مدخل من قبل المستخدم وتكون مكونات(ارقام) المصفوفه مابين

الصفروالواحد و تكون عشوائيه ويكون هناك شرط للتوزيع الارقام بحث

يكون مجموع كل صف =1 ومجموع كل عامود=1

فأذا تححق هذا الشرط ينتهي البرنامج

وقمت بعمل البرنامج بطريقه متواضعه بأستخدام امر rand ( )

وداله الشرط if ولكن واجهة كثير من المشاكل ارجوا من لديه

اي خلفيه عن الموضوع ان لا يبخل وجزاكم الله خير الجزاء ......

#3
Write your Program and  I have to help you
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#4

اشكر جميع من ساهم وسوف ارفق البرنامج

لكي نحاول لحل هذه المشكله

#include
#include
#include
#include 
#include 
void matrix(void); //this line for use function
int main(void)
{
matrix();   //comment

return 0;
}
void matrix(void)  {

saad:
int s,sum_s1=0,sum_s2=0,sum_m1=0,sum_m2=0,m,x,A[6][6],a,b,n,nn;
int sum_s[10]={0,0,0,0,0,0,0,0,0,0},sum_m[10]={0,0,0,0,0,0,0,0,0,0};

clrscr();
printf("ntPlease wite");

randomize();
for(s=1;s<4;s++)      //loop 1
{ printf("n");
for(m=1;m<5;m++)     //loop 2
{
A[m]= rand() % 2;
//printf("thh=[%d][%d]",s,m);
printf("t%d",A[m]);
//for(n=1;n<6;n++) {
if(s==1) {
sum_s=sum_s+A[m]; }
if(s==2) {
sum_s=sum_s+A[m]; }
if(s==3) {
sum_s=sum_s+A[m]; }
/*if(s==4) {
sum_s=sum_s+A[m]; }
if(s==5) {
sum_s=sum_s+A[m]; }      */
if(m==1) {
sum_m[m]=sum_m[m]+A[m]; }
if(m==2) {
sum_m[m]=sum_m[m]+A[m]; }
if(m==3) {
sum_m[m]=sum_m[m]+A[m]; }
/*if(m==4) {
sum_m[m]=sum_m[m]+A[m]; }
/*if(m==5) {
sum_m[m]=sum_m[m]+A[m]; }   //  }     */


 }
//else;
 }



//for(nn=1;nn<5;nn++) {
if(sum_s[1]<1) goto saad;
if(sum_s[2]<1) goto saad;
if(sum_s[3]<1) goto saad;
//if(sum_s[4]<1) goto saad;
//if(sum_s[5]<1) goto saad;
if(sum_s[1]>1) goto saad;
if(sum_s[2]>1) goto saad;
if(sum_s[3]>1) goto saad;
//if(sum_s[4]>1) goto saad;
//if(sum_s[5]>1) goto saad;
if(sum_m[1]<1) goto saad;
if(sum_m[2]<1) goto saad;
if(sum_m[3]<1) goto saad;
//if(sum_m[4]<1) goto saad;
//if(sum_m[5]<1) goto saad;
if(sum_m[1]>1) goto saad;
if(sum_m[2]>1) goto saad;
if(sum_m[3]>1) goto saad;
//if(sum_m[4]>1) goto saad;
//if(sum_m[5]>1) goto saad;

if(sum_s[1]==1&&sum_s[2]==1&&sum_s[3]==1)
printf("n**********************************************n");
else

if(sum_m[1]==1&&sum_m[2]==1&&sum_m[3]==1)
printf("n**********************************************n");
else


printf("n**********************************************n");
}
#5
#include 
#include
#include
#include
#include 
#include 

const int MAXCOLS=10;
const int MAXROWS=10;
int Matrix[MAXROWS][MAXCOLS];

void initMatrix();
void setValuesInMatrix(void); //this line for use function
int checkOneRow(int rowindex);
int checkOneCol(int colindex);
int chekAllCols();
int checAllRows();
int checkMatrix();
int colsCount,rowsCount;

void printMatrix();

int main(void)
{
	cout<<"nplease give the Count of Rows: ";
	cin>>rowsCount;
	cout<<"nplease give the Count of Cols: ";
	cin>>colsCount;
	cout<<"n";

	int Counter=0;
	initMatrix();
	while(checkMatrix()!=1)
	{
		Counter++;
		setValuesInMatrix();
	    printMatrix();
		cout<<"n Try Nr: "<


	}
	printMatrix();
	cout<<"Try Nr: "<
return 0;
}

void initMatrix()
{

	for(int i=0;i		for(int j=0;j			 Matrix[j]=0;

}

void setValuesInMatrix(void) //this line for use function
{
	for(int i=0;i		for(int j=0;j			Matrix[j]=rand()%2;

}
int checkOneRow(int rowindex)
{
	int k;
	int ok=0;
	int sum=0;
	for(k=0;k		sum+=Matrix[rowindex][k];
	if(sum==1)
		ok=1;
	return ok;
}

int checkOneCol(int colindex)
{
	int k;
	int ok=0;
	int sum=0;
	for(k=0;k		sum+=Matrix[k][colindex];
	if(sum==1)
		ok=1;
	return ok;
}

int chekAllCols()
{

	int ok=1;
	int k;

	for(k=0;k		ok=(ok&&checkOneCol(k));

	return ok;
}

int checAllRows()
{
	int ok=1;
	int k;

	for(k=0;k		ok=(ok&&checkOneRow(k));

	return ok;

}

int checkMatrix()
{
	int ok=(checAllRows()&&chekAllCols());
	return ok;
}

void printMatrix()
{

	for(int i=0;i	{
		for(int j=0;j			cout<    cout<<"n";

	}//for i
}
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#6

لك مني الف تحيه يا اخ khwlani

ولك مني الف شكر(f)

وتقدير وكل احترام لكل حرف سطرته اناملك

وجزاك الله عني خير الجزاء وكم اثلج صدري

تعاونك معي ,,, نفعنا الله بعلمك ونفع به

اخواني العرب :o

#7

Sorry I cann't write in Arabic becuse I haven't Arabic system

Thanks is only for ALLAh
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء

هذا الموضوع مغلق.

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…