Close Back

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<rajesh.h>

main()
{
	int i,size,asc,dsc,array[25];
	char resp[10];
	clrscr();
	printf("\nA program to find weather a mvector is sorted");
	do
	{
		do
		{
			printf("\nHow many elements do you want to enter\n(less than 25) ");
			scanf("%d",&size);
		}
		while(size > 25 || size <= 1);	/*size 1 is meaningless here*/
		printf("\nEnter the array:");
		for(i=0;i<size;i++)
			scanf("%d",&array[i]);
		asc = 1;
		dsc = 1;
		for(i = 0;i<size-1;i++)
		{
			if(array[i] > array[i+1])
				asc = 0;
			if(array[i] < array[i+1])
				dsc = 0;
		}
		if(asc)
			printf("\nThe array is in ascending order");
		else if(dsc)
			printf("\nThe array is in descending order");
		else
			printf("\nThe vector isn\'t sorted");
		printf("\nDo again(y/n) ");
		scanf("%9s",resp);
	}
	while(*resp == 'y' || *resp == 'Y');
	getch();
}