Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please only expression, variables, printf, scanf, if then else, while loop, and

ID: 643844 • Letter: P

Question


Please only expression, variables, printf, scanf, if then else, while loop, and arrays.

We um, define the left to right Diagonals (Figure on Left below) of a matrix and the Right to left Diagonals (Figure on Right below) as two special traversals of the elements of a matrix as illustrated below. Write a C program to accept an input square matrix of dimension N called A. Now, compute two vectors from the elements in A- the first vector must include elements of A listed in order of the Left-to-Right Diagonals and the second vector must include elements of A listed in order of the Right-to-Left Diagonals. Now, compute the dot product of these two vectors and print out the scalar value.

Explanation / Answer

#include
#include
void displayLFD(int n);
void getData(int n);
void display(int n);
int arr[10][10];
void main()
{
int n;
printf("The range of the matrix:");
scanf("%d",&n);

getData(n);
display(n);
displayLFD(n);
getch();
}

void getData(int n)
{
int i,j;

for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&arr[i][j]);
}
}
}

void display(int n)
{
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf(" %d",arr[i][j]);
}
printf(" ");
}
}

void displayLFD(int n)
{
int i,j,k;

for(int i=0;i printf("Slice %d:",i);
for(int j=0,k=i; j=0; j++,k--)
printf("%d ",arr[j][k]);}