联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2025-01-02 08:48

1. Please briefly describe what the run time error is in C language.

2. Write a program that prints each command-line argument on a new line.

Example:

Input in CMD: ./program hello world

Output:

3. Write a program that reads a line of text from the user using fgets and prints it

back.

Example:

Input from the keyboard:

Output to the screen:

4. Write a program that reads a line of text using fgets and calculates its length

(excluding the newline character).

Example:

Input from the keyboard:

Output to the screen:

5. Define a structure Rectangle with two members: length and width. Ask the user

to input the length and width of a rectangle. Calculate and output the area and

perimeter of the rectangle.

Input:

Output:

6. Define a structure Student with the following members:

⚫ name (a string)

⚫ roll_number (an integer)

⚫ marks (a float)

Write a program to:

⚫ Declare an array of 3 Student structures.

⚫ Ask the user to input the details of each student.

⚫ Print the name and marks of the student with the highest marks.

Input:

‘Output:

--- Student with Highest Marks ---

Name: Eva

Marks: 90.00

7. Write a C program that defines a Student structure with fields for name and

age. Create an array of students, populate it with sample data, and sort the

array by student names in alphabetical order.

Instructions:

1. Define a Structure:

• Create a struct named Student with the following members:

• char name[50]; to store the student's name.

• int age; to store the student's age.

2. Create an Array of Structures:

• Define an array of Student structures to store information for at

least 5 students.

3. Populate the Array:

• Initialize the array with sample data for student names and ages.

4. Sort the Array:

• Write a function to sort the array by student names in alphabetical

order using a suitable sorting algorithm.

5. Print the Sorted Array:

• Display the sorted list of students, including their names and age.

Input:

Student 1:

Name: Tom

Age: 32

Student 2:

Name: Dick

Age: 43

Student 3:

Name: Jane

Age: 24

Output:

Dick: 43

Jane: 24

Tom: 32


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp