Ms. Shravani, Ms. Jahnavi, Ms. Latha K, Ms. Ganapriya, and Ms. Shashikala P goes for festival shopping in Orion Mall. Each one purchases 5 items that are of the same type and Ms. Sharavani Maintains the cost of each purchase of all 5. Help Mr. Sharavani to store the cost of all items purchased by her and her friends. In the end, they want to know among all purchases which is the maximum cost. Generate a C Application for the same
Requirement
1. Declare a 2D array
2. Read the cost of all items
3. Find the maximum cost amongst all items.
4. Display the maximum cost.
#include <stdio.h>
int main()
{
int r=5;
int c=5;
//Declare a 2D array
int items[5][5];
//Read the cost of all items
printf("Enter the cost of all the items: ");
for (int i=0;i<r;i++){
for(int j=0;j<c;j++){
scanf("%d",&items[i][j]);
}
}
//Find the maximum cost amongst all items.
int max=items[0][0];
for (int i=0;i<r;i++){
for(int j=0;j<c;j++){
if (items[i][j]>max)
max=items[i][j];
}
}
// Display the maximum cost.
printf("Maximum cost is: %d",max);
return 0;
}
Comments
Leave a comment