Answer to Question #214213 in C for ABHINEET GAUR

Question #214213

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.


1
Expert's answer
2021-07-07T18:38:54-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS