Sunday, January 20, 2013

Practicle test help

1)Create function to take two integer arguments and compare them and if no1 > no2 then swam them.

                 void swapGreater(int number1, int number2);

2)Create function to take an array as a input argument and shift larger walue in to the last array element.

                 void arraySort(int *array);


                 first array look - 12, 300 ,4 ,56 , 67, 3
                 after swap  - 12 , 4,56,67,3,300


3) Create function to read values to array from key board.

                void takeInputs(int *array);

4) Create function to dsplay values from array .

                void displayValues(int *array);

5)
 Create the main mehod and do the following.

                      create array with 6 elements;
                      take values from keybord using takeInputs function.
                     do 5 times arraySort function call to the array.
                     display the array using displayValues function

** this question is 100% not the same , but the program u have to write for this problem is same as the practical test.

ANSWER..............

#include<stdio.h>

void swapGreater(int *no1, int *no2);

void arraySort(int array[]);

void takeInput(int *array);

void display(int *array);


main(){


int array[6],i;

takeInput(array);

printf("before sort !! \n");

display(array);

for(i=0;i<5;i++){

arraySort(array);

}

printf("after sort !! \n");

display(array);


}


void swapGreater(int *no1, int *no2){

int temp;

if(*no1 > *no2){

temp = *no1;

*no1 = *no2;

*no2 = temp;

}



}


void arraySort(int array[]){

int i;

for(i=0;i<5;i++){

swapGreater(&array[i],&array[i+1]);

}



}


void takeInput(int *array){

int i;

printf("enter 6 values \n");

for(i=0;i<6;i++){

scanf("%d",&array[i]);

}


}


void display(int *array){

int i;

for(i=0;i<6;i++){

                printf("%d \n",array[i]);

        }


}