// To arrange entered numbers in ascending order
#include <stdio.h>
void swapper(int*,int*);
void ascender(int,int[]);
int main()
{ int i,values[6];
printf("Enter 5 numbers");
for(i=1;i<=5;i++){ scanf("%d",&values[i]);}
ascender(i,&values[0]);
printf("The ascending order of the numbers is");
for(i=1;i<=5;i++){ printf("%d ",values[i]);}}
void ascender(int i, int* values){
int j=0;
for (i=1;i<=4;i++){
for(j=1;j<=4;j++){
if (values[j+1]< values[j]){ swapper( &values[j],&values[j+1]); }}}}
void swapper(int *a,int *b){
int temp; temp=*b; *b=*a ; *a=temp;}
No comments:
Post a Comment