spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Program to code zigzag matrix


This should work for you:

#include <stdio.h>

int main() {

    int rows, columns;
    int rowCount, columnCount, count = 0;

    printf("Please enter rows and columns:
>");
    scanf("%d %d", &rows, &columns);


    for(rowCount = 0; rowCount < rows;
rowCount++) {

        for(columnCount = 1; columnCount <=
columns; columnCount++) {

            if(count % 2 == 0)
                printf("%4d " ,
(columnCount+(rowCount*columns)));
            else
                printf("%4d " ,
((rowCount+1)*columns)-columnCount+1);    

        }
        count++;
        printf("
");
    }


    return 0;

}

Input:

5 5

Output:

 1  2  3  4  5
10  9  8  7  6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25

Categories : C

Related to : Program to code zigzag matrix
python - how to compute correlation-matrix with nans in data-matrix
You can convert all nan values to zeros using np.nan_to_num() and then proceed further. Demo: >>> data array([[ 5.1, 3.5, 1.4, 0.2], [ 4.9, 3. , nan, 0.2], [ 4.7, 3.2, 1.3, nan], [ nan, 3.1, 1.5, 0.2]]) >>> np.cov(data.T) array([[ nan, nan, nan, nan], [ nan, 0.04666667, nan, nan],

Categories : Python
Eigen sparse matrix multiplications seem to compute full matrix
Basically, the document is sightly confusing for me at least. the way to do it is simply: SpMat mat_3 = mat_1 * mat_2 No dense matrix is created along the way. Eigen rocks!

Categories : C++
matrix inside matrix when multiplying symbolic matrices
The problem seems to be the K = C2^(16/57). Taking the root of a matrix is not trivial and solutions don't always exist. That's why MATLAB cannot resolve this expression. Try for example: A = syms('A',[3,3]); % create 3x3 symbolic matrix B = A^(1/3); % calculate the 3rd root of A The result will be ans = matrix([[a1_1, a1_2, a1_3], [a2_1, a2_2, a2_3], [a3_1, a3_2, a3_3]])^(1/3)

Categories : Matlab
Filling up a matrix with computed values of another matrix
Assuming that the block of columns are based on the first two characters, i.e. A1, A2, we can split this into different blocks by using substr to extract the first two characters from the column names and use this as index to split. Then, we can either use apply with range and diff to get the result or use pmax and pmin. indx <- substr(colnames(df), 1,2) If the grouping is not based on t

Categories : R
C: Return even number in array program by using pointers, why does my program crush after printing the result
for(i = 0; i <= sizeof(test); i++){ printf("%d ", *test[i] ); } sizeof(test) isn't the number of elements in the array test, it's sizeof(int*) which is 8 (bytes), assuming you're on a 64-bit system. It's returning the size of a pointer to a memory address, not the actual length of the array. So your loop goes outside the bounds of the array which probably causes your problem. Al

Categories : C
Recently Add
Rewrite of IDA decompiled function
Computing the average of grades in C
passing structures to functions
Use semaphores for handling sockets in C
How to search for a string pattern inside html, coding in C?
sprintf invalid format '%d'
Why can't this c program run correctly?
Low Pass filter in C
Child process does not print anything
C: datatypes. sqrt function working with int why?
How to implement Serial Port Profile Link Command used in ConnectBlue Bluetooth Module?
Rerunning cancelled pthread
How to print out a string that is pointed to by a char pointer?
Can unverified scanf call cause an undefined behavior?
nested structures in C
Portable Makevars for R package using C, GSL and OpenMP with help of Rcpp
program doesn't run(getting RUN FINISHED Segmentation fault core dumped)
Finding the sign of a Lua number, from C
Width of symbols created by gcc's objectcopy
Strange behavior when using free in c program
Can't open image C
Strange C code - dynamic arrays?
C program printing weird characters
Fault in decimal to binary in c
How to detect broken pipe on input?
How can I ivestigate use of the register keyword in C?
File scaning with fscanf
why gcc generates "leal -8240(%ebp), %eax; cmpl $1, %eax; ja XXX" instead of jmp instruction?
Wierd Problems With My Own Custom Written Word Search Algorithm
Trouble with making a shell in C
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.