C Programming Tutorial

 
 
 
 

Image

# include<stdio.h>
# include \"/usr/include/sys/types.h\"
# include \"/usr/include/sys/shm.h\"
# include \"/usr/include/sys/ipc.h\"
# include \"/usr/include/sys/sem.h\"
# include\"forkjoin.h\"
# include\"sharedlib.h\"
int main()
{

    int Mat[10][10];
    int Vect[10];
    int *resVect;

    int MatRow,MatCol;

    int iVal[100],kVal[100];    
    int iCount,jCount,kCount;
    int shmid1,shmid2;    


    int Index=0,nProc,shmid[6],id;



        printf(\"Enter Number of Rows :\");
    scanf(\"%d\",&MatRow);

    nProc=MatRow;

    printf(\"Enter Number of Columns :\");
    scanf(\"%d\",&MatCol);        

        resVect=(int *)sshared(sizeof(int)*MatRow,&shmid[0]);        


    printf(\"\\n Enter Elements of Matrix ...\\n\");
        for(iCount=0;iCount<MatRow;iCount++)  
        {
                for(jCount=0;jCount<MatCol;jCount++)
                {
                        printf(\"Mat[%d][%d] :\",iCount,jCount);
                        scanf(\"%d\",&Mat[iCount][jCount]);                        
                }
        resVect[iCount]=0;
        }

        printf(\"\\n Enter Elements of Vector ...\\n\");
        for(iCount=0;iCount<MatCol;iCount++)
        {                
             printf(\"Vect[%d] :\",iCount);
                scanf(\"%d\",&Vect[iCount]);                
        }

        for(iCount=0;iCount<MatRow;iCount++)
        {                
                for(kCount=0;kCount<MatCol;kCount++)
                {
                    iVal[Index] = iCount;                                
                    kVal[Index] = kCount;
                    Index++;
                }                
        }

        printf(\"\\n Matrix ... \\n\");
        for(iCount=0;iCount<MatRow;iCount++)
        {
                for(jCount=0;jCount<MatCol;jCount++)
                {
                        printf(\"%d\\t\",Mat[iCount][jCount]);
                }
                printf(\"\\n\");
        }
        printf(\"\\n Vector ... \\n\");
        for(iCount=0;iCount<MatCol;iCount++)
        {
            printf(\"%d\\n\",Vect[iCount]);
        }

    id=process_fork(nProc);

        for(Index=id;Index<MatRow*MatCol;Index+=nProc)
        {
                iCount=iVal[Index];         
                kCount=kVal[Index];
                resVect[iCount] += Mat[iCount][kCount]*Vect[kCount];
        }        
    process_join(nProc,id);

        printf(\"\\nMultiplication of Matrix and Vector is ...\\n\");
        for(iCount=0;iCount<MatRow;iCount++)
        {
            printf(\"%d \\n\",resVect[iCount]);                                        
        }

    return 0;
}

    Related Post:
  1. Example of file functions like fread(), fwrite(), fopen(), fclose() and fseek()

  2. Program that implements circular queue as an array

  3. Program to find sum of the elements of the array using self scheduling

  4. Program that illustrates use of printf statement

  5. PROGRAM FOR CHECK THE CONDIDATE IS ELIGIBLE OR NOT

  6. Program to compare one string s2 to another string s1. Print the difference of first unmatched characters using strcmp function from string.h

  7. Program to create processes using fork() and check zombie state

  8. Program to find vowels, constants and digits from a file using threading

  9. Program to search and/or replace a word in C program

  10. Program to implement a multi-access threaded queue with multiple threads inserting and multiple threads extracting from the queue

  11. Singly Linked list with following operations INSERT AT STARTING, INSERT AT MIDDLE, INSERT AT END, DELETE FIRST NODE, DELETE LAST NODE, DELETE MIDDLE

  12. Program to add to matrices using pointers

  13. Program to find smaller or greater numbers using if statement

  14. Program to find area of circle

  15. Program to display diamond shape triangle which contains * in it

  16. Program for Number Conversion from Decimal to Binary, Decimal to Octal, Decimal to Hexa, Binary to Octal, Binary to Hexa, Octal to Hexa

  17. Program that implements depth first search algorithm.

  18. Program to copy elements of one array to another for n number of processes

  19. Program to find volume of sphere

  20. Program that takes a string from user and prints the total number of characters, words and lines present in the string.

 
 
Didn't find what you were looking for? Find more on Program to multiply matrix (10 x 10) with a vector using Indirect Scheduling