/* This is a program in C language to check that an array is sorted or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int array[10],i;
clrscr();
// ask user to enter numbers in array
printf("Enter 10 numbers \t:");
for(i=0;i<10;i++)
scanf("%d",&array[i]);
// to check the sorted array in ascending order
for(i=1;i<10;i++)
{
if(array[i]<array[i-1])
{
printf("This array is not sorted in ascending order");
getch();
exit(0);
}
}
printf("This array is sorted in ascending order");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int array[10],i;
clrscr();
// ask user to enter numbers in array
printf("Enter 10 numbers \t:");
for(i=0;i<10;i++)
scanf("%d",&array[i]);
// to check the sorted array in ascending order
for(i=1;i<10;i++)
{
if(array[i]<array[i-1])
{
printf("This array is not sorted in ascending order");
getch();
exit(0);
}
}
printf("This array is sorted in ascending order");
getch();
}
Comments
Post a Comment