Thread: problem with my C code

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    problem with my C code

    Code:
    #include "stdio.h";
    
    
    
    int main() 
    {
    	int arrayA[10][10]; 
    	int arrayB[10][10]; 
    
    	int row , col , arrayB_row_cnt , arrayB_col_cnt, arrayA_row_cnt , arrayA_col_cnt, size_cnt ;
    	row = col = arrayB_row_cnt = arrayB_col_cnt = arrayA_row_cnt  = arrayA_col_cnt = size_cnt = 0;
    
    	
    	printf( "Enter the value for row: " );
    	scanf ( "%d", &row );
    
    	printf ( "Etner the valye for col: " );
    	scanf ( "%d" , &col);
    		
    	
    
    	printf( "Please fill the Array with values\n" ) ;
    	
    	while ( row != arrayA_row_cnt)
    	{
    	
    		/*printf ( "row == %d and cnt_row == %d", row , arrayA_row_cnt );*/
    		while ( col != arrayA_col_cnt)
    		{
    			
    			 /*printf ( "col  == %d and cnt_col  == %d", col , arrayA_col_cnt );*/
    
    			printf ( "Array[%d][%d] = ",  arrayA_row_cnt ,  arrayA_col_cnt );
    			scanf ( "%d", &arrayA[arrayA_row_cnt][arrayB_row_cnt]);		
    			
    			arrayA_col_cnt++;
    		
    		}
    
    		arrayA_col_cnt = 0;
    		arrayA_row_cnt++;
    	} 
    
    
    	arrayA_row_cnt = 0;
    	arrayA_col_cnt = 0;
    
    
    	while ( row != arrayA_row_cnt )
    	{	
    		
    		while ( col != arrayA_col_cnt )
    		{
    			arrayB[arrayB_row_cnt][arrayB_col_cnt] = arrayA[arrayA_row_cnt][arrayA_col_cnt];
    				
    			printf ( "arrayA[%d][%d] = %d and ArrayB[%d][%d] = %d\n" , arrayA_row_cnt , arrayA_col_cnt ,
    				  arrayA[arrayA_row_cnt][arrayA_col_cnt], arrayB_row_cnt , arrayB_col_cnt , arrayB[arrayB_row_cnt][arrayB_col_cnt] );		
    			arrayB_row_cnt++;
    			arrayA_col_cnt++;	
    		}
    
    		arrayA_col_cnt = 0;
    		arrayB_row_cnt = 0;
    
    		arrayA_row_cnt++;
    		arrayB_col_cnt++;
    	}
    
    	
    
    	return 0;
    
    }
    output is

    Code:
    [ansur@shiva asm]$ ./6-P7C
    Enter the value for row: 2
    Etner the valye for col: 3
    Please fill the Array with values
    Array[0][0] = 1
    Array[0][1] = 2
    Array[0][2] = 3
    Array[1][0] = 4
    Array[1][1] = 5
    Array[1][2] = 6
    arrayA[0][0] = 3 and ArrayB[0][0] = 3
    arrayA[0][1] = 10826915 and ArrayB[1][0] = 10826915
    arrayA[0][2] = 10720404 and ArrayB[2][0] = 10720404
    arrayA[1][0] = 6 and ArrayB[0][1] = 6
    arrayA[1][1] = 0 and ArrayB[1][1] = 0
    arrayA[1][2] = 0 and ArrayB[2][1] = 0
    [ansur@shiva asm]$
    where am i going wrong ?
    The programm gets the transpose of a matric .That is Rows are turned into colum for the other Array .The opposite .


    thanks
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Look again:
    Code:
    scanf ( "%d", &arrayA[arrayA_row_cnt][arrayB_row_cnt]);

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    thanks alot .. I need to getting used to correcting my ability to spot miniture things .. thanks again
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 11:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2003, 12:53 AM