0% found this document useful (0 votes)
16 views

Aayush Neupane - Assignment VII - Two Dimensional Array

Uploaded by

jhyasshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Aayush Neupane - Assignment VII - Two Dimensional Array

Uploaded by

jhyasshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

/*Write a program to declare two arrays of 3 rows and 3 columns [2 of Matrix of 3*3].

take user
input for those arrays and do the following:
a. Find the sum of two matrices and print in the console.
b. Check if two matrices are equal.
c. Check if two matrices are identity matrices.
d. Find the sum of upper triangle of a matrix */

#include<stdio.h>
int main()
{
int i,j;
int arr[3][3],arr2[3][3];
int sum[3][3];
int flag;

printf("enter the elements of the array 1\n");


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

printf("enter the elements of the array 2\n");


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

}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(arr[i][j]==arr2[i][j]){
sum[i][j]=arr[i][j]+arr2[i][j];
}
}
printf("\n");
}
printf("The sum of two matrix are;\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%d\t",sum[i][j]);
}
printf("\n");
}

printf("\n");

//b.Checking if the triangle is equal

for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(arr[i][j]==arr2[i][j]){
flag=1;
}
else{
flag=0;
}
}
}
if(flag==1){
printf("They are equal");
}
else{
printf("They aren't equal");
}
}

//identity matrix

//identity and upper traingle sum

#include<stdio.h>
int main()
{
int i,j;
int arr[3][3];
int flag;
int sum=0;

printf("enter the elements of the array 1\n");


for(i=0;i<3;i++){
for(j=0;j<3;j++){
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%d\t",arr[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(i==j){
if(arr[i][j]==1){
flag=1;
}
else{
flag=0;
break;
}

}
else{
if(arr[i][j]==0){
flag=1;
}
else{
flag=0;
break;
}
}
}
}
if(flag==1){
printf("The enetered matrix is identity\n");
}
else{
printf("It is not identity matrix\n");
}
printf("******************************************************\n");

//d . Sum of upper triangle of the matirx

for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(i<=j){
sum+=arr[i][j];
}
}
}
printf("The sum of elements of upper triangle is %d",sum);
return 0;
}

2) //Write a program to read names of your favorite 5 actor and store and in character array of
two dimension
#include<stdio.h>
int main(){
char ch[5][15];
int i,j;
printf("enter names of your favourite actor : ");
for(i=0;i<5;i++){
for(j=0;j<14;j++){
scanf("%c",&ch[i][j]);
}
}
printf("names of my favourite actors are :\n");
for(i=0;i<5;i++){
for(j=0;j<14;j++){
printf("%c",ch[i][j]);
}
printf("\n");
}
return 0;
}

You might also like