C Programming code for Sum, Avg, Max in Data Structures

Write a Modular C Programming code for Finding Sum, Avg, and Max in Data Structures

Read the number of students, read their information and display the details of the Books & also finding the maximum pages, Average price, etc…:

CODE:

#include<stdio.h>

struct books
{
    char name[20];
    int page;
    float price;
    char author[20];
}b;
struct books read(struct books);
void display(struct books);
void max_pages(struct books,struct books,struct books);
void avg_price(struct books,struct books,struct books);

main()
{
struct books b1,b2,b3;
printf("\nEnter Details of Book1: ");
   b1=read(b1);
   printf("\nEnter Details of Book2: ");
   b2=read(b2);
   printf("\nEnter Details of Book3: ");
   b3=read(b3);
   max_pages(b1,b2,b3);
   avg_price(b1,b2,b3);
}

struct books read(struct books b)
{
    printf("\nEnter the Name: ");
    scanf("%s",&b.name);
    printf("Enter the Pages: ");
    scanf("%d",&b.page);
    printf("Enter the price: ");
    scanf("%f",&b.price);
    printf("Enter the author: ");
    scanf("%s",&b.author);
    printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
    return(b);
}

void display(struct books b)
{
    printf("The details of Book are");
    printf("\nName: %s",b.name);
    printf("\nPages: %d",b.page);
    printf("\nPrice: %f",b.price);
    printf("\nAuthor: %s",b.author);
    printf("\n\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
}

void max_pages(struct books b1,struct books b2, struct books b3)
{
    printf("\nThe maximum pages book have the following Details:\n");
    if (b1.page>b2.page && b1.page>b3.page)
        display(b1);
    else if (b2.page>b1.page && b2.page>b3.page)
        display(b2);
    else
        display(b3);

}

void avg_price(struct books b1, struct books b2, struct books b3)
{

    float sum, avg;
    sum= b1.price + b2.price + b3.price;
    avg= sum/3;
    printf("The avarage Price of Books = %f", avg);
}

 

OUTPUT

Enter Details of Book1:
Enter the Name: Science
Enter the Pages: 200
Enter the price: 250
Enter the author: Thor

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Book2:
Enter the Name: Avathar
Enter the Pages: 1000
Enter the price: 2000
Enter the author: James

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Book3:
Enter the Name: KGF
Enter the Pages: 3000
Enter the price: 450
Enter the author: RockyBhai

+++++++++++++++++++++++++++++++++++++++++++++++++

The maximum pages book have the following Details:
The details of Book are
Name: KGF
Pages: 3000
Price: 450.000000
Author: RockyBhai

+++++++++++++++++++++++++++++++++++++++++++++++++
The avarage Price of Books = 900.000000
Process returned 0 (0x0)   execution time : 82.552 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 







Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!