Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This program request the user to enter 10 integers and sort them in ascending order
- #include <stdio.h>
- int main()
- {
- /*========================================*/
- /* Declare and initialize working storage */
- /*========================================*/
- int outer=0; // outer loop index
- int inner=0; // inner loop index
- int counter=0; // generic loop counter index
- int temp=0; // to hold the swap value temporary
- int u_array[10]; // integer array to hold 10 integers
- /*=============================================================*/
- /* Prompt user to enter the 10 integers to be sorted and store */
- /* them in the u_array. */
- /*=============================================================*/
- printf("Please enter the 10 numbers \n");
- for (counter = 0; counter < 10; counter++)
- scanf("%d", &u_array[counter]);
- /*=================================*/
- /* print out u_array after sorting */
- /*=================================*/
- printf("The numbers arranged in ascending order are given below \n");
- for (counter = 0; counter < 10; counter++)
- printf("%d\n", u_array[counter]);
- return 0; // return control to OS
- }
- // This program is a demonstration of a simple function call
- #include <stdio.h>
- int calTotal(); // you need to declare the function here, take note of the format
- int main()
- {
- // declare and initialise working storage
- int num1=0; // this variable holds the first number from user
- int num2=0; // this variable holds the second number from the user
- int total=0; // this variable holds the total of the two numbers
- // prompt user to enter two numbers
- printf("Please enter the first number :");
- scanf("%d", &num1);
- printf("\nPlease enter the second number :");
- scanf("%d", &num2);
- // invoke funtion calTotal() to compute the sum of num1 and num2
- // the return vale from the function is assigned to the variable total
- total = calTotal(num1, num2);
- //print the total as returned from th function call
- printf("\n\nThe sum of the %d and %d is %d", num1, num2, total);
- return 0;
- }
- // function calTotal is used to calculate the sum of two numbers
- // function will return an integer value to the calling function, i.e., main()
- int calTotal(int first, int second)
- {
- int sum = 0; //declare local variable to hold the sum
- sum = first + second;
- return sum; // return to calling function, i.e., main()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement