NUMBER OF MINIMUM AND MAXIMUM OF AN UNSORTED ARRAYCode CrazeJan 27, 20231 min read#include <stdio.h>int main() { int n,m,i,j; int a[100]; int choice; printf("\nEnter the range of array : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter Element : "); scanf("%d",&a[i]); } printf("\n----Before Sorting----\n"); for(i=0;i<n;i++) { printf("----%d",a[i]); } printf("\n----After Sorting----\n"); for(i=0;i<n;i++) { for(j=i;j<n;j++) { if(a[i]>=a[j]) { int temp; temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(i=0;i<n;i++) { printf("----%d",a[i]); } printf("\nEnter Your Choice(1/0) : "); scanf("%d",&choice); while(choice) { printf("\nEnter Your Choice(min=1/max=2) : "); scanf("%d",&choice); switch(choice) { case 1: { printf("\nHow Many Minimum Elements You Require : "); scanf("%d",&m); printf("\n"); for(i=0;i<m;i++) { printf("----%d",a[i]); } } case 2: { printf("\nHow Many Maximum Elements You Require : "); scanf("%d",&m); printf("\n"); for(i=n-1;i>=(n-m);i--) { printf("----%d",a[i]); } } default: printf("\nRepeat"); } }}
#include <stdio.h>int main() { int n,m,i,j; int a[100]; int choice; printf("\nEnter the range of array : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter Element : "); scanf("%d",&a[i]); } printf("\n----Before Sorting----\n"); for(i=0;i<n;i++) { printf("----%d",a[i]); } printf("\n----After Sorting----\n"); for(i=0;i<n;i++) { for(j=i;j<n;j++) { if(a[i]>=a[j]) { int temp; temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(i=0;i<n;i++) { printf("----%d",a[i]); } printf("\nEnter Your Choice(1/0) : "); scanf("%d",&choice); while(choice) { printf("\nEnter Your Choice(min=1/max=2) : "); scanf("%d",&choice); switch(choice) { case 1: { printf("\nHow Many Minimum Elements You Require : "); scanf("%d",&m); printf("\n"); for(i=0;i<m;i++) { printf("----%d",a[i]); } } case 2: { printf("\nHow Many Maximum Elements You Require : "); scanf("%d",&m); printf("\n"); for(i=n-1;i>=(n-m);i--) { printf("----%d",a[i]); } } default: printf("\nRepeat"); } }}
Stack Using QueueA stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...
Queue Using StackA queue can be implemented using two stacks in C. The basic idea is to use one stack for enqueue operations and another for dequeue...
Queue Using Array#include <stdio.h> #include<stdlib.h> #include<math.h> #define size 5 int queue[size]; int front = -1; int rear = -1; void enque(void);...
Comentários