Question

1 4 7 10 2 5 8 11 3 6 9 12 I want to print...

1 4 7 10
2 5 8 11
3 6 9 12

I want to print this matrix in c language.

How did this formula come out? (3 * j + i + 1);

#include <stdio.h>

int main()
{
int y[3][4];
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
printf("%d ", 3 * j + i + 1);
printf("\n");
}
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

i is for rows -- # of rows = 3

j is for columns -- # of cols = 4

Since indices start with 0, we are taking i+1 to get the the number in the row.

In each column, we have 3 numbers. So, we have 3 * j.

Add a comment
Know the answer?
Add Answer to:
1 4 7 10 2 5 8 11 3 6 9 12 I want to print...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Debug to print output "2 3 5 6 8 11": #include <stdio.h> #include <stdlib.h> int main()...

    Debug to print output "2 3 5 6 8 11": #include <stdio.h> #include <stdlib.h> int main() {    int i, j, n; int A[] = {2, 3, 5, 5, 5, 6, 8, 11, 11, 11};    n = sizeof(A) / sizeof(int);    for (i = 0; i < n - 1; i++){        if (A[i] != A[i + 1]) {            for (j = 1; j < n - 1; j++) {                A[j]...

  • 10 What does the last printf in this code print to the screen? a)n-7 b)n- 0...

    10 What does the last printf in this code print to the screen? a)n-7 b)n- 0 c)n--1 d) None of the above 鬐include< stdio. h> int main) int n-0 for (n-7: n<O; n-- printf (n") printf ("n *%d", n); - return 11-What does the code print to the screen? 鬐include< stdio.h> void fun (int) int main) b) 8 d) None of the above fun (3) return void fun (int a) int x-10 while(a !_ 3 x > s} if a...

  • 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...

  • Trying to debug a C program given to me. This is what I was given... //...

    Trying to debug a C program given to me. This is what I was given... // Program to read numeric elements (including decimals) into a 3X3 matrix and display them #include<stdio.h> int main(void) {    int size = 3, Matrix[size][size];    printf("Enter 9 elements of the matrix:\n") for (int i = 0, i <=size, i++}        for (int j = 0, j <= size, i++)            scan("%c", Matrix1[2][2]);    diplay(Matrix) float display(int Matrix1[][], int size) (   ...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

  • 1 #include <stdio.h> 2 3 11 Remember this written by the 4 // "new guy down...

    1 #include <stdio.h> 2 3 11 Remember this written by the 4 // "new guy down the hall". 5 6 pint main(int argc, char *argv[]) { 7 int a = 200; 8 int b = 300; 9 int c = 500; 10 if (a > 400) 11 b += 10; 12 else 13 if (c > 300) b += 50; 14 else b += 20; C += 10; 15 C += 100; 16 if (b > 800) 17 C +=...

  • Could you do that in C language? Here is the code which we got #include <stdio.h>...

    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...

  • 3) (10 pts) For the purposes of this question, a permutation of size n is any...

    3) (10 pts) For the purposes of this question, a permutation of size n is any ordering of the integers 0, 1, 2, ..., n-1. We define a spaced-out permutation of size n to be a permutation such that two consecutive terms in the permutation differ by at least 2. For example, [0, 2, 4, 1, 3] is a spaced out permutation of size 5, and [5, 2, 4, 0, 3, 1] is a spaced out permutation of size 6,...

  • #include<stdio.h> int functionl (int x, int y); int main() int ij=2,k; for(i=1;i<=5; i++) k = function1(ij);...

    #include<stdio.h> int functionl (int x, int y); int main() int ij=2,k; for(i=1;i<=5; i++) k = function1(ij); printf("k=%d\n",k); return 0; int function] (int x, int y) int z; z=x*2+y; return z;

  • Suppose that you have three programs that are suppose to print a house diagram in a...

    Suppose that you have three programs that are suppose to print a house diagram in a collaborative manner. (i) prog1.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“                      ^^^^^^^^^^^^                       \n”);     printf(“           ^^^^^^^^^^^            ^^^^^^^^^^^            \n”);     printf(“^^^^^^^^^^^                                  ^^^^^^^^^^^ \n”);     printf(“     |                                            |      \n”);     printf(“     |                                            |      \n”);     exit(1); } (i) prog2.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“     |                                             |    ...

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