Aayush Neupane - Assignment VII - Two Dimensional Array
Aayush Neupane - Assignment VII - Two Dimensional Array
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;
}
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");
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
#include<stdio.h>
int main()
{
int i,j;
int arr[3][3];
int flag;
int sum=0;
}
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");
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;
}