an oil factory has N number of containers and each has a different capacity
Answers
Answer:
what is the meaning of the question
Complete Question:
An oil factory has N number of containers and each has a different capacity. During renovation, the manager decided to make some changes with the containers. He wishes to make different pairs for the containers in such a way that in the first pair the container of maximum capacity is paired with the container of minimum capacity, and so on for the rest of the containers, to maintain a balance throughout all the pairs of containers. Write a program to make different pairs of containers in such a way that the first container in the pair is of maximum capacity and second container in the pair is of minimum capacity. write the c program
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int N;
printf("Enter total number of containers : ");
scanf("%d" , &N);
int A[N];
printf("Enter the capacity of each connected : \n");
for(int i = 0 ; i < N ; i++)
{
scanf("%d" , &A[i]);
}
for(int i = 0 ; i < N ; i++)
{
for(int j = 0 ; j < N - 1 - i ; j++)
{
if(A[j] < A[j+1])
{
int temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;
}
}
}
printf("Pairs are : \n");
for(int i = 0 ; i < N ; i++)
{
if(i != N-1)
{
printf("%d , %d\n",A[i],A[N-1]);
N = N-1;
}
else
{
printf("%d",A[i]);
}
}
return 0;
}
Output 1:
Enter total number of containers : 6
Enter the capacity of each connected :
10
90
30
70
50
55
Pairs are :
90 , 10
70 , 30
55 , 50
Output 2:
Enter total number of containers : 5
Enter the capacity of each connected :
10
90
30
70
50
Pairs are :
90 , 10
70 , 30
50