Thread: how to change this simple opeation into power operation..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    how to change this simple operation into power operation..

    I got this simple operation of 2 equal matrix multiplication:
    How to change it so if i enter a number
    it will put the matrix into the power of the input number.

    How do i transform some how this simple multiplication operation into a power operation.

    Ii have tried to use temporary matrix to save the local multiplication.
    and multiply by it on the next step
    but its not working
    ??

    Code:
    #include <stdio.h>
    
    
    
    
    int main(){//star
        int rows,cols,jndex,input;
        int sum2=0;
        printf("enter rows and cols [1..50] ==> ");
        scanf("%d %d",&rows,&cols);
        int matrix[rows][cols];
        int sum[rows][cols];
        int temp[rows][cols];
        int transpose [cols][rows];
        int index,kndex,tndex,gndex,lndex;
    printf("enter power:");
          scanf("%d",&input);
    
        for (index=0;index<rows;index++){
    
            for (kndex=0;kndex<cols;kndex++){
               matrix[index][kndex]=0;
               sum[index][kndex]=0;
               temp[index][kndex]=0;
               transpose[index][kndex]=0;
            }//end inner for
        }//end outer for
    
    printf("enter numbers in a row for a matrix:");                                                 //stat input
    
          for (index=rows-1;index>=0;index--){
    
               for (kndex=cols-1;kndex>=0;kndex--){
    
                 scanf("%d",&matrix[index][kndex]);
    
                 transpose [kndex][index]=matrix[index][kndex];
               }
    
            }
    
    getchar();  //needed because of scanf()
                                                 //end input
    
    
    
    
    
    
    
    
    
    
                                                 //start power operation
    
    
    
                                           //start temp=matrix
        for (gndex=0;gndex<rows;gndex++){
    
            for (lndex=0;lndex<cols;lndex++){
    
               temp[index][kndex]=matrix[index][kndex];
    
            }//end inner for
        }//end outer for
                                        //end temp=matrix
      for (tndex=0;tndex<input;tndex++){
    
                        for(index=0;index<rows;index++) {
                           for(jndex=0;jndex< cols;jndex++) {
    
                                     sum[index][jndex]=0;
                                        for(kndex=0;kndex<cols;kndex++) {
                                            sum[index][jndex] = sum[index][jndex] + temp[index][kndex] * matrix[kndex][jndex];
                                        }
                            }
                         }
    
    
    
                                           //start temp=sum
        for (gndex=0;gndex<rows;gndex++){
    
            for (lndex=0;lndex<cols;lndex++){
    
               temp[index][kndex]=sum[index][kndex];
    
            }//end inner for
        }//end outer for
                                        //end temp=sum
      }
    
                                              //end power operation
    
    
                    //start print
    
            for (index=0;index<rows;index++){
    
               for (kndex=0;kndex<cols;kndex++){
    
                 printf("%d ",sum[index][kndex]);
               }
               printf("\n");
            }
    
                                              //end print
    
                    printf("\n");
    
    
    
    
    
        return 0;
    }//end main func
    Last edited by transgalactic2; 12-20-2008 at 01:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  2. help with calculating change from a dollar
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2002, 03:58 PM
  3. (structure+array+pointer)to make a simple database
    By frankie in forum C Programming
    Replies: 5
    Last Post: 04-26-2002, 05:14 PM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM