Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 10
  4.  
  5. void Swap(int*, int*);
  6. void Triple(int *ptrD);
  7. int BubbleSort(int A[MAX], int size, int order);
  8.  
  9.  
  10. int main()
  11. {
  12.     int A, B;
  13.  
  14.     printf("Enter value for a and b: ");
  15.     scanf("%d %d",&A, &B); //Enters the Value of A and B
  16.  
  17.     int *ptrA = &A;  //Points to adress A
  18.     int *ptrB = &B;  //Points to adress B
  19.  
  20.     Swap(ptrA,ptrB); //Swap function
  21.     printf("%d %d\n", *ptrA, *ptrB);
  22.  
  23.     int D; //Used in Triple function
  24.  
  25.     printf("Enter a value for D used in Triple: ");
  26.     scanf("%d", &D); //Enters the Value of D
  27.  
  28.     Triple(&D); //calling the function triple
  29.     printf("%d\n",D);
  30.  
  31.     int Array[MAX] = {1,3,2,0};
  32.     int size;
  33.     int r;
  34.     int choice;
  35.  
  36.     size = 4;
  37.     //printf("Enter the size of the array : ");
  38.     //scanf("%d", &size);
  39.  
  40.     //printf("Enter and element into the array : ")
  41.     //for (r=0;r<size;r++)
  42.     //{
  43.     //    scanf("%d", &Array[r]);
  44.     //}
  45.  
  46.     printf("Pick which order to accend the array, 1 for accending, -1 for decending :");
  47.     scanf("%d", &choice);
  48.     BubbleSort(Array,size,choice);
  49.  
  50.     for (r=0;r<size;r++)
  51.     {
  52.         printf("%d", Array[r]);
  53.     }
  54.  
  55.     return 0;
  56. }
  57.  
  58. void Swap (int *ptrA, int *ptrB)
  59. {
  60.     int holder=0;
  61.     holder = *ptrA;
  62.     *ptrA = *ptrB;
  63.     *ptrB = holder;
  64.  
  65. }
  66.  
  67. void Triple(int *ptrD)
  68. {
  69.     *ptrD = *ptrD + *ptrD + *ptrD;
  70. }
  71.  
  72. BubbleSort(int A[MAX], int size, int choice)
  73. {
  74.     int r,c;
  75.  
  76.     for (r=0;r<size;r++)
  77.     {
  78.         for (c=0;c<size;c++)
  79.             if (choice == 1)
  80.             {
  81.                 if (A[c] > A[c+1])
  82.                 Swap(&A[c],&A[c+1]);
  83.             }
  84.             else if (choice == -1)
  85.             {
  86.                 if (A[c] < A[c+1])
  87.                 Swap(&A[c],&A[c+1]);
  88.             }
  89.     }
  90.  
  91.     return 1;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement