Example: Write a program to create a cell structure BOOK that stores information about the BOOK: title, author’s name, page number, and price, and accepts input and output.

The code is as follows:

#include <stdio.h>
#include <string.h>

/* Customize the BOOK structure */
struct book
{
	char name[50];
	/* Define an array variable to store the name */
	char author[25];
	/* Define array variables to store the author */
	int pages;
	/* Defines an integer variable to store the number of pages */
	float price;
	/* The canonical variable is used to store the price */
};

int main(a)
{
	struct book b1;
	/* Struct variable */
	printf("\n\t Please enter details of the book :\n");
	printf("\ n the title:");
	gets(b1.name);
	    /* The above is: prompt message and enter */
	printf("\ n the author:");
	gets(b1.author);
	    /* The above is: prompt message and enter */
	printf("\ n pages.");
	scanf("%d",&b1.pages);
	    /* The above is: prompt message and enter */
	printf("\ n prices.");
	    scanf("%f",&b1.price);
	    /* The above is: prompt message and enter */
	
	printf("Details of \n\n\n\t book");
	    /* The following information is displayed: */
	printf("\n Title: %s",b1.name);
	/* Prints the result */
	printf("\n Author: %s",b1.author);
	/* Prints the result */
	printf("\n Pages: %d",b1.pages);
	/* Prints the result */
	printf("\n \n\n" : % 5.2F yuan \n\n\n\n",b1.price);
	/* Prints the result */
}
Copy the code

The output running window is as follows:



Other exercises this week

C programming column

① Write an input function to receive n integers from the keyboard and store them in an array of integers. Call this function in the main function to compute the sum of the n integers.

② The user enters a set of data until a return is entered and the data is put into an array. Requirements: first bubble sort array, output results; Then prompt the user “whether to insert data”, if you want to insert data, insert the inserted data into the array, and still output in order; And then you get the maximum and the minimum, and you output.

③ In the postal system, the charge is so stipulated, when the parcel weight <=10 kg, according to the charge of 0.25 yuan per kg; If more than 10 kg, the excess part will be charged 0.34 yuan, the rest will be charged 0.25 yuan. The user is requested to input the weight of the parcel, please output the postage payable.

The sixth week ④ party provisions: boys, more than 18 years old can drink, no more than 18 years old, drink; Girls, over 20 years old, can drink alcohol, not over 20 years old, drink drinks; Please input student gender and student age, and according to the input to judge what to drink!

Beijing University Jade bird requirements: in the recommendation of employment, according to the following criteria to measure

1) : If the number of projects is less than 5, employment cannot be recommended

2) : The number of projects is less than 6 to 10: only small companies in Chongqing can be recommended

3) : The number of projects is less than 11 to 20: any company in Chongqing can be recommended

4) : The number of projects is more than 20: may enter foreign companies

C programming > sixth week ⑥ Input a string of characters, statistics write letters, and emphasize that statistics must use functions.

Write a program to create a structure called BOOK that stores information about the BOOK: title, author’s name, page number, and price, and accepts input and output.

C language programming > the sixth week ⑧ write procedures to achieve magic square matrix.

The harder you work, the luckier you get! Come on, Aoli!!