Provide a time complexity analysis for this code   #include int main(){ //Required matrices and variables int matrix1[6][6]; int matrix2[6][6]; int matrix3[6][6]; int i,j,k,n,m,l; //Reads number from user printf("Enter a number : "); scanf("%d", &n);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Provide a time complexity analysis for this code

 

#include<stdio.h>

int main(){

//Required matrices and variables
int matrix1[6][6];
int matrix2[6][6];
int matrix3[6][6];
int i,j,k,n,m,l;

//Reads number from user
printf("Enter a number : ");
scanf("%d", &n);

//Value for diagonal
m = 2*n;
//Temperary variable of 'n'
l = n;
//Creates matrix 1
for(i = 0; i< 6; i++){
k = l;
for(j = 0; j<6; j++){
if(j == (6-i-1))
matrix1[i][j] = m;
else if(j > (6-i-1))
matrix1[i][j] = (k++ + 1);
else matrix1[i][j] = k--;
}
l--;
}
//Prints matrix 1
for(i = 0; i< 6; i++){
printf("[");
for(j = 0; j<6; j++)
printf("%c ", (char)matrix1[i][j]);
printf("]\n");
}

printf("\n\n");

//Creates matrix 2
l = n;
for(i = 0; i<6 ; i++)
for(j = 0; j<6; j++){
if(i < 3 && j < 3)
matrix2[i][j] = l;
else if(i < 3 && j >= 3)
matrix2[i][j] = l + 1;
else if(i >= 3 && j < 3)
matrix2[i][j] = l + 2;
else matrix2[i][j] = l + 3;
}

//Prints matrix 2
for(i = 0; i< 6; i++){
printf("[");
for(j = 0; j<6; j++)
printf("%c ", (char)matrix2[i][j]);
printf("]\n");
}

printf("\n\n");

//Determines the difference between firts digit and diagonal digit
if(n % 2 == 1)
l = n - 12;
else l = n - 10;

//Creates matrix 3
for(i = 0; i< 6; i++){
k = l;
for(j = 0; j<6; j++){
if(j == (6-i-1))
matrix3[i][j] = n;
else if(j > (6-i-1)){
k = k - 2;
matrix3[i][j] = k;
}
else {
matrix3[i][j] = k;
k = k + 2;
}
}
l = l + 2;
}

//Prints matrix 3
for(i = 0; i< 6; i++){
printf("[");
for(j = 0; j<6; j++)
printf("%c ", (char)matrix3[i][j]);
printf("]\n");
}
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education