C program for sorting, C/C++ Programming

Assignment Help:

C Program for SORTING

# include stdio.h>

void main()

{

          char a;

          int *p;

          int i,j,temp;

          clrscr();

          p=&i;

          p++;

          for(i=1;i<=5;i++)

          {

                   printf("Enter the %d no.",i);

                   scanf("%d",&*(p+i));

          }

printf("ENTER A FOR ASENDING OR D FOR DECENDING ORDER -");

scanf("%c",&a);

          if(a=='a')

          {

                   for(i=1;i<=5;i++)

                   {       

for(j=1;j<=5;j++)

                             {

                             if(*(p+i)<*(p+j))

                             {

                                      temp=*(p+i);

                                       *(p+i)=*(p+j);

                                      *(p+j)=temp;

                             }

                             }

                   }

          }

          else if(a=='d')

          {

                   for(i=1;i<=5;i++)

                   for(j=1;j<=5;j++)

                   {

                             if(*(p+i)>*(p+j))

                             {

                                      temp=*(p+i);

                                      *(p+i)=*(p+j);

                                      *(p+j)=temp;

                             }

                   }

          }

          printf("\nThe sorted no is.");

          for(i=1;i<=5;i++)

          {

                   printf("\n%d",*(p+i));

          }

          getch();

}

 

 


Related Discussions:- C program for sorting

Stream input and output functions, Within C we access external devices by ...

Within C we access external devices by means of a pointer i.e. address. The address could point to any memory mapped device i.e. Ram, Rom, Duart, Disk drives etc. Therefore there i

Operator overloading - c++ program, Operator overloading - c++ program: ...

Operator overloading - c++ program: Write a program in c to define operator overloading. class matrix{                   private :                 int x[2][2];

Wap to print the largest number from any 10 numbers, WAP TO PRINT THE LARGE...

WAP TO PRINT THE LARGEST NUMBER FROM ANY 10 NUMBERS #include stdio.h> #include conio.h>   void main()   {                    int a[10],i,max;

What is the reward of operator overloading?, A: you can exploit by overload...

A: you can exploit by overloading standard operators on a class, the intuition of the users of that class. This allow users program in the language of the problem domain instead of

Lua and C++ sprite animation, How would I use variables of a C++ object wit...

How would I use variables of a C++ object within a Lua function, and then call the Lua function from C++ code?

Decodethecode, how to decode the numerals to string..

how to decode the numerals to string..

What is b-tree, B-tree: A B-tree is an also called balanced m-way tree. A ...

B-tree: A B-tree is an also called balanced m-way tree. A node of the tree may have many records or key and pointers to children. It is also called as the balanced sort tree. It s

Variable, what is local and global variable?give me some example to underst...

what is local and global variable?give me some example to understand better

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd