Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 10
- void Swap(int*, int*);
- void Triple(int *ptrD);
- int BubbleSort(int A[MAX], int size, int order);
- int main()
- {
- int A, B;
- printf("Enter value for a and b: ");
- scanf("%d %d",&A, &B); //Enters the Value of A and B
- int *ptrA = &A; //Points to adress A
- int *ptrB = &B; //Points to adress B
- Swap(ptrA,ptrB); //Swap function
- printf("%d %d\n", *ptrA, *ptrB);
- int D; //Used in Triple function
- printf("Enter a value for D used in Triple: ");
- scanf("%d", &D); //Enters the Value of D
- Triple(&D); //calling the function triple
- printf("%d\n",D);
- int Array[MAX] = {1,3,2,0};
- int size;
- int r;
- int choice;
- size = 4;
- //printf("Enter the size of the array : ");
- //scanf("%d", &size);
- //printf("Enter and element into the array : ")
- //for (r=0;r<size;r++)
- //{
- // scanf("%d", &Array[r]);
- //}
- printf("Pick which order to accend the array, 1 for accending, -1 for decending :");
- scanf("%d", &choice);
- BubbleSort(Array,size,choice);
- for (r=0;r<size;r++)
- {
- printf("%d", Array[r]);
- }
- return 0;
- }
- void Swap (int *ptrA, int *ptrB)
- {
- int holder=0;
- holder = *ptrA;
- *ptrA = *ptrB;
- *ptrB = holder;
- }
- void Triple(int *ptrD)
- {
- *ptrD = *ptrD + *ptrD + *ptrD;
- }
- BubbleSort(int A[MAX], int size, int choice)
- {
- int r,c;
- for (r=0;r<size;r++)
- {
- for (c=0;c<size;c++)
- if (choice == 1)
- {
- if (A[c] > A[c+1])
- Swap(&A[c],&A[c+1]);
- }
- else if (choice == -1)
- {
- if (A[c] < A[c+1])
- Swap(&A[c],&A[c+1]);
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement