Thread: I need urgent help on my hw about rows(deadline is sunday 23:59) please help me

  1. #1
    Registered User
    Join Date
    Jul 2015
    Posts
    3

    I need urgent help on my hw about rows(deadline is sunday 23:59) please help me

    I need to do like this
    I need urgent help on my hw about rows(deadline is sunday 23:59) please help me-hw-jpg

    Why my code does not work ?

    Description about my code:
    There are 4 ways that are right,down,left,up. These are matrix's ways. I described as a 'way' --> 'way=way%4'

    And The numbers start from 0 and continue like 1,2,3,4,5,6,7,8,9 and then 0 again so I use this control ' number=number%10'

    please help me this is my very important homework

    Code:
    #include "stdio.h"
    
    void fillthematrix(int dizi[10][10], int size){
    
    
        int imax,jmax,i,j;
        int imin=0,jmin=0,way=0,number=0;
    
    
        imax=size-1;
        jmax=size-1;
    
    
    
    
    while (imin<=imax || jmin<=jmax){
        way=way%4;
    
    
        if(way==0){
            for(j=jmin;j<=jmax;j++){
                number=number%10;
            dizi[imin][j] = number;
    
    
            }
    
    
            ++number;
            ++way;
    }
    
    
        else if(way==1){
    
    
            for(i=imax;i>imin;i--){
                number=number%10;
            dizi[i][jmax] = number;
    
    
            }
            ++way;
            ++number;
    
    
          }
    
    
        else if(way==2){
    
    
            for(j=jmin;j<jmax;j++){
    
    
                number=number%10;
            dizi[imax][j] = number;
            }
    
    
            ++way;
            ++number;
    
    
    
    
    }
    
    
        else if(way==3){
    
    
        for(i=imax-1;i>imin;i--){
    
    
                number=number%10;
            dizi[i][jmin] = number;
        }
        ++way;
        ++number;
    
    
            }
    
    
    
    
          jmax--;
          imax--;
          imin++;
          jmin++;
    
    
    
    
    
    
    
    
         }
    }
    
    
    void printonscreen(int dizi[10][10], int boyut){        
    int i,j;
    
    
    for(i=0;i<size;i++){
        for(j=0;j<boyut;j++){
            printf("%d",dizi[i][j]);
    }
    printf("\n");
    }
    
    
    }
    
    
    
    
    
    
    int main(){
        int dizi[10][10];
        int size;
    
    
        while (1){
        printf("Please enter your matrix's size or press -1 if you want to quit.");
        scanf("%d",&size);
    
    
        if(size==-1){
           printf("seeyou");
           break;
         }
    
    
                 fillthematrix(dizi[size][size],size);
                 printonscreen(dizi[size][size],size);
    
    
        }
    
    
    
    
    
    
      return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    These two lines are likely wrong; did not look at the rest of program.


    Code:
                 fillthematrix(dizi[size][size],size);
                 printonscreen(dizi[size][size],size);
    Likely you want
    Code:
                 fillthematrix(dizi,size);
                 printonscreen(dizi,size);
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jul 2015
    Posts
    3
    I did what you said but only first line is corrent. here is the output
    I need urgent help on my hw about rows(deadline is sunday 23:59) please help me-hwz-jpg

  4. #4
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    I have not check it, but the last lines in the function fillthematrix() decrease all mins and increase all max.
    Code:
    …
            jmax--;
            imax--;
            imin++;
            jmin++;
    …
    But if the way == 0, then you should only increace jmin.
    If the way == 1, decrease imax.
    If the way == 2, decrease jmax.
    If the way == 3, increase imax.

    Additional, what all if-statements have together is
    Code:
    …
            ++number;
            ++way;
    …
    You can generalize this two statements after the last if-statements.

    And i think, the order in the if-statements is false.
    Code:
    …
        if (way == 0) {
            for( j = jmin ; j <= jmax ; j++ ) {
                number = number % 10;
                dizi[imin][j] = number;
            }
    …
    Because you change the number every time while you write in one way (direction).
    I think it should be:
    Code:
    …
        if (way == 0) {
            number = number % 10;
            for( j = jmin ; j <= jmax ; j++ ) {
                dizi[imin][j] = number;
            }
    …
    You declare your matrix in main with size 10/10.
    If the user input a number greater then 10, you run in undefined behavior.
    You should chatch this as you do it with -1.
    Also, what is, if the user enter -2 (or lower)?
    Your contition can look like this:
    Code:
    …
            if (size < 0) {
                printf("seeyou\n");
                break;
            }
    
            else if (size > 10) {
                printf("too big. exit.\n");
                break;
            }
    …
    This is all untested. Thats only ideas by a quick look over your code.
    And as you can see, i have inserted a couple of space to make the code better readable.
    Last edited by WoodSTokk; 07-04-2015 at 09:16 AM.
    Other have classes, we are class

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Please make sure your code is neatly formatted and indented.
    https://en.wikipedia.org/wiki/Indent_style

    Compile with maximum warnings:

    Code:
    /*
    main.c||In function 'printonscreen':|
    main.c|108|error: 'size' undeclared (first use in this function)|
    main.c|108|error: (Each undeclared identifier is reported only once|
    main.c|108|error: for each function it appears in.)|
    main.c||In function 'main':|
    main.c|139|warning: passing argument 1 of 'fillthematrix' makes pointer from integer without a cast|
    main.c|3|note: expected 'int (*)[10]' but argument is of type 'int'|
    main.c|140|warning: passing argument 1 of 'printonscreen' makes pointer from integer without a cast|
    main.c|104|note: expected 'int (*)[10]' but argument is of type 'int'|
    ||=== Build finished: 3 errors, 2 warnings ===|
    */

  6. #6
    Registered User
    Join Date
    Jul 2015
    Posts
    3
    Thank you a lot WoodSTokk!!

    You were a little bit wrong about min max increase decrease issues but your vision very helpful for me

    Sharing correct one maybe someone'll wonder

    There are first correct two ways.

    Code:
    if(way==0){
                 number=number%10;
    
    
            for(j=jmin;j<=jmax;j++){
    
    
            dizi[imin][j] = number;
    
    
            }
    
    
            ++number;
            ++way;
            ++imin;
    }
    
    
        else if(way==1){
    
    
              number=number%10;
    
    
            for(i=imax;i>=imin;i--){
    
    
            dizi[i][jmax] = number;
    
    
            }
            ++number;
            ++way;
            --jmax;
    
    
          }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easter Sunday
    By Anhur in forum C Programming
    Replies: 4
    Last Post: 03-08-2013, 12:49 AM
  2. Assignment deadline
    By stawp in forum Tech Board
    Replies: 4
    Last Post: 11-15-2012, 01:38 PM
  3. [C++0x] Comments to the FCD approaching deadline
    By Mario F. in forum General Discussions
    Replies: 0
    Last Post: 07-19-2010, 06:53 AM
  4. Can someone please help deadline tomorow
    By scott1990 in forum C Programming
    Replies: 47
    Last Post: 06-02-2010, 04:55 PM
  5. Sunday Smut
    By Fordy in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 07-21-2002, 09:22 PM

Tags for this Thread