Thursday, March 3, 2011

User-Defined Functions

Write a program that uses a function to sort an array of integers.
A program to sort an array of integers using the function sort() is given. Its output clearly shows that a function can change the values in an array passed as an argument.

#include <stdio.h>
void sort(int m, int x[ ]);
void main()
   {
       int i;
       int marks[5] = {40, 90, 73, 81, 35};
       printf("Marks before sorting\n");
       for(i = 0; i < 5; i++)
   printf("%d ", marks[i]);
       printf("\n\n");
       sort (5, marks);
       printf("Marks after sorting\n");
       for(i = 0; i < 5; i++)
   printf("%-4d", marks[i]);
       printf("\n");                                          
       getch();
   }

No comments:

Post a Comment