Session 12

 

Session 12: Write a Program that is correct but still not reliable. Justify your answer. Make 

 necessary assumptions. 

Ans: 

#include <stdio.h>

int main() {

  int a[10][10], transpose[10][10], r, c;

  printf("Enter rows and columns: ");

  scanf("%d %d", &r, &c);


  // asssigning elements to the matrix

  printf("\nEnter matrix elements:\n");

  for (int i = 0; i < r; ++i)

  for (int j = 0; j < c; ++j) {

    printf("Enter element a%d%d: ", i + 1, j + 1);

    scanf("%d", &a[i][j]);

  }


  // printing the matrix a[][]

  printf("\nEntered matrix: \n");

  for (int i = 0; i < r; ++i)

  for (int j = 0; j < c; ++j) {

    printf("%d  ", a[i][j]);

    if (j == c - 1)

    printf("\n");

  }


  // computing the transpose

  for (int i = 0; i < r; ++i)

  for (int j = 0; j < c; ++j) {

    transpose[j][i] = a[i][j];

  }


  // printing the transpose

  printf("\nTranspose of the matrix:\n");

  for (int i = 0; i < c; ++i)

  for (int j = 0; j < r; ++j) {

    printf("%d  ", transpose[i][j]);

    if (j == r - 1)

    printf("\n");

  }

  return 0;

}

Output -: 


Problems -:

1.) When we input the value the rows & columns for which we want the matrix. If there value extended 4x4. Then the program output is so long & it takes more time to process.

2.) It's difficult to understand by another person. Not enough comments help us to know what the specific loop go through & does. 

Comments

Popular posts from this blog

Session 4: DFD, ERD, and Data Dictionary

Session 13

Session-1 Scope Statement for the Online Railway Reservation System