0% found this document useful (0 votes)
11 views4 pages

8 Multidimensional Arrays حل-1

Uploaded by

morshidwww2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

8 Multidimensional Arrays حل-1

Uploaded by

morshidwww2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Fundamentals of Computer Programming UNIVERSITY OF SCIENCE & TECHNOLOGY

Faculty of Engineering
2nd Level Dep. of Electronics
Engineering

Programming Sheet # 8
(Multidimensional Arrays)
1) Write a program that declares an array of type (double) with size 3*3, and initializes the elements,
and then prints it on the screen.
#include<stdio.h>
main()
{
int i,j;
double x[3][3]={{1,2,3},{4,5,6},{7,8,9}};
printf("\nThe array x[3][3]=\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%lf\t",x[i][j]);

printf("\n");
}
}
2) Write a program that declares two arrays of type (int) with size 2*2, then takes the arrays elements
from the user, finally determines the summation and subtraction of the two arrays and prints the
results.
#include<stdio.h>
main()
{
int i,j;
int x[2][2],y[2][2],z[2][2],w[2][2];

printf("Enter array x[2][2]\n");


for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
scanf("%d",&x[i][j]);

printf("Please enter array y[2][2]\n");


for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
scanf("%d",&y[i][j]);

for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
{
z[i][j]=x[i][j]+y[i][j];
w[i][j]=x[i][j]-y[i][j];
}

Sheet #8 - Multidimensional Arrays Eng. Ali Al-Ashwal 1


printf("\nx+y=\n");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
printf("%d\t",z[i][j]);

printf("\n");
}
printf("\nx-y=\n");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
printf("%d\t",w[i][j]);

printf("\n");
}
}
3) Write a program that declares an array of type (float) with size 3×4, takes the array elements from
the user, then find the transpose of the array and prints the result.
#include<stdio.h>
main()
{
int i,j;
float x[3][4],T[3][4];

printf("Enter array x[3][4]\n");


for(i=0;i<=2;i++)
for(j=0;j<=3;j++)
scanf("%f",&x[i][j]);

printf("\nThe array x=\n");


for(i=0;i<=2;i++)
{
for(j=0;j<=3;j++)
printf("%.1f\t",x[i][j]);

printf("\n");
}

for(i=0;i<=3;i++)
for(j=0;j<=2;j++)
T[i][j]=x[j][i];

printf("\nThe transpose array=\n");


for(i=0;i<=3;i++)
{
for(j=0;j<=2;j++)
printf("%.1f\t",T[i][j]);

printf("\n");
}
}
Sheet #8 - Multidimensional Arrays Eng. Ali Al-Ashwal 2
4) Write a program that declares two arrays of type (int) with size 2*2, then takes the arrays elements
from user, finally determines the product of the two arrays and prints the results.
#include<stdio.h>
main()
{
int i,j,k;
int x[2][2],y[2][2],z[2][2];

printf("Enter array x[2][2]\n");


for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
scanf("%d",&x[i][j]);

printf("Please enter array y[2][2]\n");


for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
scanf("%d",&y[i][j]);

for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
z[i][j]=0;
for(k=0;k<=1;k++)
z[i][j]+=x[i][k]*y[k][j];
}
}
printf("\nx*y=\n");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
printf("%d\t",z[i][j]);

printf("\n");
}
}

Sheet #8 - Multidimensional Arrays Eng. Ali Al-Ashwal 3


5) Write a program to takes three degrees for five students from user, then prints the degrees,
summation, and average for all students.
#include<stdio.h>
main()
{
int i,j;
float x[5][3],sum;

for(i=0;i<=4;i++)
{
printf("Enter three degrees of student (%d):\n",i+1);
for(j=0;j<=2;j++)
scanf("%f",&x[i][j]);
}

printf("\n\tdeg(1)\tdeg(2)\tdeg(3)\tsum\taverage\n");
for(i=0;i<=4;i++)
{
sum=0;
printf("stud(%d)\t",i+1);

for(j=0;j<=2;j++)
{
printf("%.2f\t",x[i][j]);
sum+=x[i][j];
}

printf("%.2f\t%.2f\t",sum,sum/3);

printf("\n");
printf("---------------------------------------------");
printf("\n");
}
}

Sheet #8 - Multidimensional Arrays Eng. Ali Al-Ashwal 4

You might also like