C Programming Tutorial

 
 
 
 
#include<stdio.h>
#include<pthread.h>

struct minmax
{
    int min;
    int max;
};
typedef struct minmax s;

int a[10],n;

void *min_max();
s *smain,*sthread;

main()
{
    int finalmin,finalmax,i;
    pthread_t tid;

    smain=(s*)malloc(sizeof(s));

    printf(\"Enter the limit : \");
    scanf(\"%d\",&n);

    printf(\"\\nEnter the elemenats :\");
    for(i=0;i<n;i++)
    {
        printf(\"\\na[%d] : \",i);
        scanf(\"%d\",&a[i]);
    }

    smain->min=smain->max=a[0];

    pthread_create(&tid,NULL,min_max,NULL);

    for(i=0;i<n/2;i++)
    {
        if(a[i] < smain->min)
            smain->min=a[i];
        if(a[i] > smain->max)
            smain->max=a[i];
    }

    pthread_join(tid,NULL);

    if(smain->min <= sthread->min)
        finalmin=smain->min;
    else
        finalmin=sthread->min;

    if(smain->max >= sthread->max)
        finalmax=smain->max;
    else
        finalmax=sthread->max;

    printf(\"\\nMin : %d \\n Max : %d\",finalmin,finalmax);
}

void *min_max()
{
    int i;

    sthread=(s*)malloc(sizeof(s));

    sthread->min=sthread->max=a[n/2];

    for(i=a[n/2];i<n;i++)
    {
        if(a[i] < sthread->min)
            sthread->min=a[i];
        if(a[i] > sthread->max)
            sthread->max=a[i];
    }
}

    Related Post:
  1. Use of continue statement

  2. Program for count number of digits in string

  3. Basic GAUSS ELIMINATION METHOD, GAUSS ELIMINATION WITH PIVOTING, GAUSS JACOBI METHOD, GAUSS SEIDEL METHOD

  4. Program to add record in a file, search record by name telephone number and display all records from a file

  5. Program to find the length of a string taken from user without using strlen function

  6. Program that implements breadth first search algorithm

  7. Program to read a file name, serach it in the whole Hard Drive and delete it if found

  8. Example - 2 of illustrating block of statement

  9. N-R METHOD OF NON LINEAR EQUATION

  10. Program to interchange the Small and Capital Letters and Unload the TSR on occurance of @ character

  11. Program to compare one string s2 to another string s1 and also first unmatched characters without using strcmp function from string.h

  12. Program of an editor with menu bar

  13. Example to display multi dimentional array values using functions

  14. Program to interchange the Small and Capital Letters and Unload the TSR after 10 seconds using Timer Interrupt

  15. Program that illustrates arithmetic operators

  16. Program to concatenate one linked list at end of another and than to erase all nodes present in the linked list

  17. Program of histogram using self-scheduling and locking the whole bin

  18. Program to print the address of a variable along with its value

  19. PROGRAM FOR HISTOGRAM FOR INDIVIDUAL CELL OF HISTOGRAM THERE ARE SEPARATE LOCK

  20. PROGRAM USNG WHILE LOOP TO REVERSE THE DIGITS OF THE NUMBER NO IS - 12345 ANSWER IS 54321

 
 
Didn't find what you were looking for? Find more on Program to find minimum and maximum from an array using structure