0% found this document useful (0 votes)
32 views1 page

Lab cs101

Uploaded by

Mayank Bassi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Lab cs101

Uploaded by

Mayank Bassi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment

Question 1: -
Define a struct called Book with members for title, author, price, and pages. Write a program to:

• Take input for 3 books.

• Print out the details of the book with the highest price.

Question 2: -

Create a struct called Point with x and y coordinates. Write a function that takes two Point structs as
parameters and returns the distance between them as a double. Implement the function and test it
with different points.

Question 3: -

Create a struct called Point with x and y coordinates. Write a function that takes two Point structs as
parameters and returns the distance between them as a double. Implement the function and test it
with different points.

Question 4: -

Define a struct Student with members for name, roll_number, and marks (an array to hold marks for
3 subjects). Write a program to:

• Input data for 5 students.

• Write a function to calculate the average marks of each student and print the name of the
student with the highest average marks.

Question 5: -

Define an enum TrafficLight with values RED, YELLOW, and GREEN. Write a program to take user input
to select a traffic light color and print the action to be taken (e.g., "Stop" for RED, "Caution" for
YELLOW, "Go" for GREEN).

Question 6: -

Write a user-defined function int factorial(int n) that calculates the factorial of a given number n.
Write a program that:

• Takes an integer input from the user.

• Calls factorial() and prints the result.

Question 7: -

Write a user-defined function to find the largest number in an array. The function should take an
integer array and its size as parameters and return the largest number. Write a program that:

• Takes an array of 10 integers as input.

• Calls the function to find and print the largest number in the array.

You might also like