Advertisement
wadkat

sorter c

Dec 6th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.47 KB | None | 0 0
  1.  
  2. // This program request the user to enter 10 integers and sort them in ascending order
  3.  
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     /*========================================*/
  9.     /* Declare and initialize working storage */
  10.     /*========================================*/
  11.     int outer=0;        // outer loop index
  12.     int inner=0;        // inner loop index
  13.     int counter=0;      // generic loop counter index
  14.     int temp=0;     // to hold the swap value temporary
  15.     int u_array[10];    // integer array to hold 10 integers
  16.  
  17.     /*=============================================================*/
  18.     /* Prompt user to enter the 10 integers to be sorted and store */
  19.     /* them in the u_array.                        */
  20.     /*=============================================================*/
  21.         printf("Please enter the 10 numbers \n");
  22.         for (counter = 0; counter < 10; counter++)
  23.           scanf("%d", &u_array[counter]);
  24.  
  25.     /*=================================*/
  26.     /* print out u_array after sorting */
  27.     /*=================================*/
  28.         printf("The numbers arranged in ascending order are given below \n");
  29.         for (counter = 0; counter < 10; counter++)
  30.             printf("%d\n", u_array[counter]);
  31.  
  32.   return 0; // return control to OS
  33. }
  34.  
  35.  
  36.  
  37. // This program is a demonstration of a simple function call
  38.  
  39. #include <stdio.h>
  40.  
  41. int calTotal();     // you need to declare the function here, take note of the format
  42.  
  43. int main()
  44. {
  45.   // declare and initialise working storage
  46.   int num1=0;   // this variable holds the first number from user
  47.   int num2=0;   // this variable holds the second number from the user
  48.   int total=0;  // this variable holds the total of the two numbers
  49.  
  50.   // prompt user to enter two numbers
  51.   printf("Please enter the first number :");
  52.   scanf("%d", &num1);
  53.   printf("\nPlease enter the second number :");
  54.   scanf("%d", &num2);
  55.  
  56.   // invoke funtion calTotal() to compute the sum of num1 and num2
  57.   // the return vale from the function is assigned to the variable total
  58.   total = calTotal(num1, num2);
  59.  
  60.   //print the total as returned from th function call
  61.   printf("\n\nThe sum of the %d and %d is %d", num1, num2, total);
  62.  
  63.   return 0;
  64. }
  65.  
  66. // function calTotal is used to calculate the sum of two numbers
  67. // function will return an integer value to the calling function, i.e., main()
  68.  
  69. int calTotal(int first, int second)
  70. {
  71.   int sum = 0;  //declare local variable to hold the sum
  72.  
  73.   sum = first + second;
  74.  
  75.   return sum;   // return to calling function, i.e., main()
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement