اذهب إلى المحتوى
  • 0

كيف استطيع كتابه برنامج بلغه C لعمل الدوال التاليه

Bessan Jadallah

السؤال

Recommended Posts

  • 0
#include <string.h>
int mat[3][3] , b[9];
int i  , j , k  ;
/// 1
void Add(){
  /* get the matrix entries from the user */
  printf("Enter your entries for the input mat:\n");
  for (i = 0; i < 3; i++) {
       for (j = 0; j < 3; j++) {
           scanf("%d", &mat[i][j]);
       }
  }
}


/// 2
void RowTotal(){
	for( i = 0; i < 3 ; i++){
	for( j = 0; j < 3 ; j++){

	Total+=mat[i][j];
}
printf("%d" , Total);

}

/// 3
void CFunction(){


for( i = 0; i < 3 ; i++){
	for( j = 0; j < 3 ; j++){

		if(i == j ){
			printf("[%d]" , mat[i][j]);
		}

	}

}

}


//// 4

function SortMat(){

// Convert All Array to 1d array 
k =0 ;
for(i=0;i<3;i++) 
    {
        for(j=0;j<3;j++)
         b[k++]=mat[i][j];
    }


 /// sort the 1d array 
 int temp ;
   for (i=0;i<9;i++)
    {
         for (j=0;j<(8-i);j++)
        {
               if(b[j]>b[j+1])
            {
                 temp = b[j];
                b[j] = b[j+1];
                b[j+1] = temp;
            }
        }
    }
/// conver 1d to 2d 


 k=0;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            arr[i][j]=b[k];
            k++;
        }
 
    }

}

int Max(){
int matmax = mat[0][0];

for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            if(mat[i][j] > matmax){
matmax = mat[i][j];

}
        }
        
    }
return matmax;

}

///6


void PrintArr(){

for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d ",mat[i][j]);
        }
        printf("\n");
    }


}

/// 7 
void Total(){
int Tot = 0 ;
for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            Tot+=mat[i][j];
        }
        
    }


printf("\nTotal is : %d" , Tot);


}

}

void Main(){
 // call function here
Add();
RowTotal();
CFunction();
SortMat();
printf("%d" , Max());
PrintArr();
Total();


}

Exe.c

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...