-->

WAP to input 'n' numbers and sort them in an order. PAss array as a parameter.

in turboc++
---------------------------------------------------------------------------------------------------------------
//WAP to input 'n' numbers and sort them in an order. PAss array as a parameter.
#include<stdio.h>
#include<conio.h>
void sorting_in_array(float array[200],int size);//prototype with array and size parameters
int main()
{

float arr[200];int k;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
sorting_in_array(arr,size);//calling of function
getch();
return 0;
}

void sorting_in_array(float array[200],int size)//body line
{

int i,j,k;float te;//declaration

for(i=0;i<size;i++)//loop execution
{
    for(j=i+1;j<size;j++)
    {
        if(array[i]>array[j])//value comparison
        {
            te=array[i];
            array[i]=array[j];//swapping of values
            array[j]=te;
        }
    }
}
printf("sorted numbers are\n");
for(k=0;k<size;k++)//loop execution
{
   printf("%f\n",array[k]);//data print in sorted (ascending order)format
}
    getch();
}










------------------------------------------------------------------------------------------------------------------
in codeblocks:
-------------------------------------------------------------------------------------------------------------
//WAP to input 'n' numbers and sort them in an order. PAss array as a parameter.
#include<stdio.h>
#include<conio.h>
void sorting_in_array(float array[200],int size);//prototype with array and size parameters
int main()
{

float arr[200];int k;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
sorting_in_array(arr,size);//calling of function
return 0;
}

void sorting_in_array(float array[200],int size)//body line
{

int i,j,k;float te;//declaration

for(i=0;i<size;i++)//loop execution
{
    for(j=i+1;j<size;j++)
    {
        if(array[i]>array[j])//value comparison
        {
            te=array[i];
            array[i]=array[j];//swapping of values
            array[j]=te;
        }
    }
}
printf("sorted numbers are\n");
for(k=0;k<size;k++)//loop execution
{
   printf("%f\n",array[k]);//data print in sorted (ascending order)format
}
    getch();
}

WAP to search a number in a list of numbers using array as a parameter.

in turboc++
-------------------------------------------------------------------

/*WAP to input elements and search a number in that.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
void search_in_array(float array[200],int size,int number);//prototype with array and size and number parameters
int main()
{

float arr[200];int k,num;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
printf("enter number to be searched\n");
scanf("%d",&num);                //number input to be searched
search_in_array(arr,size,num);//calling of function
getch();
return 0;
}

void search_in_array(float array[200],int size,int number)//body line
{

int k;//declaration
int found;

for(k=0;k<size;k++)//loop execution

{
 if(number==array[k])
        {
            found=0; //assigning 0 on its finding
            break;
        }
        else
        {
            found=1;//else assigning 1
        }
}
if(found==0)//testing the condition
{
    printf("number found and number %d location is %d\n",number,k);//printing the location
}
    else
{
        printf("given number is not in the list");//printing not message
}
    getch();
}




-------------------------------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------------------
/*WAP to input elements and search a number in that.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
void search_in_array(float array[200],int size,int number);//prototype with array and size and number parameters
int main()
{

float arr[200];int k,num;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
printf("enter number to be searched\n");
scanf("%d",&num);                //number input to be searched
search_in_array(arr,size,num);//calling of function
return 0;
}

void search_in_array(float array[200],int size,int number)//body line
{

int k;//declaration
int found;

for(k=0;k<size;k++)//loop execution

{
 if(number==array[k])
        {
            found=0; //assigning 0 on its finding
            break;
        }
        else
        {
            found=1;//else assigning 1
        }
}
if(found==0)//testing the condition
{
    printf("number found and number %d location is %d\n",number,k);//printing the location
}
    else
{
        printf("given number is not in the list");//printing not message
}
    getch();
}