//WAP to ask n number from user sort them in assending order and display #include<stdio.h> #include<conio.h> void main() { int i,j,n,num[100],temp; clrscr(); printf("Enter any value of n:\n"); scanf("%d",&n); printf("Entre any value in array:\n"); scanf("%d",&num[i]); for(i=0;i<n;i++) scanf("%d",&num[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(num[i]>num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf("Sorting element of array:"); for(i=0;i<n;i++) printf("%d",num[i]); getch(); }
// WAP to enter three numbers and find middle number among them. #include<stdio.h> #include<conio.h> void main ( ) { int a , b , c ; clrscr ( ) ; printf ( "Enter three number: \n " ) ; scanf ( "%d%d%d" ,& a ,& b ,& c ) ; if ( ( a > b && a < c ) || ( a > c && a < b ) ) printf ( "%d is middle number" , a ) ; else if ( ( b > a && b < c ) || ( b > c && b < a ) ) printf ( "%d is middle number" , b ) ; else printf ( "%d is middle number" , c ) ; getch ( ) ; } Output:
Comments
Post a Comment