Question

1) Write a Function displaySpiral which displays the matrix in a spiral way as follows. If the matrix is: 4 7 1 2 3 5 8 6 Then, your function should display it as follows (different colors are used for more clarification) 1 2 3 6 9 8 745 The function header should be: void displaySpiral(int matrixD[MAX_SIZE], int size) The main program MUST be as follows (and MUST NOT be changed at all):

Could you do that in C language?

Here is the code which we got

#include <stdio.h>

#define MAX_SIZE 20

// function definitions
void displaySpiral(int matrix[][MAX_SIZE], int size);
void displayMatrix(int matrix[][MAX_SIZE], int size);
int takeInput(int inputMatrix[][MAX_SIZE]);

int main() {
        int matrix[MAX_SIZE][MAX_SIZE];
        int matrixSize = takeInput(matrix);

        printf("Displaying the whole matrix:\n");
        fflush(stdout);
        displayMatrix(matrix, matrixSize);

        printf("Now, displaying the matrix in a spiral way:\n");
        fflush(stdout);
        displaySpiral(matrix, matrixSize);

        return 0;
}

// already implemented for you
int takeInput(int inputMatrix[][MAX_SIZE]) {
        int size;
        printf("What is the size of your matrix? ");
        fflush(stdout);

        scanf("%d", &size);

        int i;
        for (i = 0; i < size; i++) {
                int j;
                for (j = 0; j < size; j++) {
                        printf("Please enter the matrix[%d][%d]: ", i, j);
                        fflush(stdout);

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

        return size;
}
// already implemented for you
void displayMatrix(int matrix[][MAX_SIZE], int size) {
        int i;
        for (i = 0; i < size; i++) {
                int j;
                for (j = 0; j < size; j++) {
                        printf("%4d", matrix[i][j]);
                        fflush(stdout);
                }
                printf("\n");
                fflush(stdout);
        }
}


// TO BE COMPLETED BY YOU :)
void displaySpiral(int matrix[][MAX_SIZE], int size) {}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Could you do that in C language? Here is the code which we got #include <stdio.h>...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int...

    Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...

  • #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here....

    #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } }    return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...

  • Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */...

    Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{    char Word[21];    int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() {    struct myWord wordList[20];    char line[100];    printf("Enter an English Sentence:\n");    gets(line);    int size = tokenizeLine(line, wordList);    printf("\n");    printf("Unsorted word list.\n");    printList(wordList, size);...

  • Debug the following matrix program in C: // Program to read integers into a 3X3 matrix...

    Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) {         char size;         double Matrix[size][size+1];         printf("Enter 9 elements of the matrix:\n");         int i;         for (i = 0: i <= size: i++)     {       int j = 0;       for (; j <= size++; j++){         scanf("%d", matrix[i--][4])       }     }         Display(Matrix,9);         return 0; void...

  • In the Source Folder (src) of this project create a new C source file called "gcd.c"....

    In the Source Folder (src) of this project create a new C source file called "gcd.c". Once again, copy the contents of the "main.c" file above into the "gcd.c" source file. Modify this program to NOT ask the user to input the second Positive Integer, if the user has entered a program terminating value for the "first" input Postitive Integer. #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { //============================== setbuf(stdout, NULL); // turns standard output buffering off int...

  • devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include...

    devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include <ctype.h> #include <termios.h> #include <sys/types.h> #include <sys/mman.h>    #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) int main(int argc, char **argv) { int fd; void *map_base = NULL, *virt_addr = NULL; unsigned long read_result, writeval; off_t target; int access_type = 'w';    if(argc...

  • please rewrite or convert this C program into Assembly language and please make a notice of...

    please rewrite or convert this C program into Assembly language and please make a notice of which function is which! #include <stdio.h> #include <stdlib.h> void printMonthYear(int mon,int year); void printDaysOfWeek(); void printDays(int mon,int year); int getFirstDayOfMonth(int mon, int year); int getNumOfDaysInMonth(int mon, int year); int main(void) {    int mon=-1; int year= -1; printf("Month : "); fflush(stdout); scanf("%d",&mon);    if(mon < 1|| mon > 12){ printf("Invalid month >.<!: %d ! Must be between 1 and 12\n",mon); return 1; } printf("Year...

  • Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 1...

    Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 100 #define maxint 10000 void dijkstra(int n,int v,int dist[],int prev[],int c[][NUM]) {    int i,j;    bool s[NUM];    for(i=1; i<=n; i++)    {        dist[i] = c[v][i];        s[i] = false;        if (dist[i]>maxint) prev[i] = 0;        else prev[i] = v;    }    dist[v] = 0;    s[v] = true;    for(i=1; i<n; i++)    {        int tmp = maxint;        int u = v;        for(j=1; j<=n; j++)            if(!(s[j]) && (dist[j]<tmp))            {                u = j;                tmp = dist[j];           ...

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • Would u help me fixing this CODE With Debugging Code with GDB #include <stdio.h> #include <stdlib.h>...

    Would u help me fixing this CODE With Debugging Code with GDB #include <stdio.h> #include <stdlib.h> #define SIZE (10) typedef struct _debugLab { int i; char c; } debugLab; // Prototypes void PrintUsage(char *); void DebugOption1(void); void DebugOption2(void); int main(int argc, char **argv) { int option = 0; if (argc == 1) { PrintUsage(argv[0]); exit(0); } option = atoi(argv[1]); if (option == 1) { DebugOption1(); } else if (option == 2) { DebugOption2(); } else { PrintUsage(argv[0]); exit(0); } }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT