-->
Showing posts with label WAP to input 'n' numbers and sort them in an order. PAss array as a parameter.. Show all posts
Showing posts with label WAP to input 'n' numbers and sort them in an order. PAss array as a parameter.. Show all posts

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();
}