0% found this document useful (0 votes)
13 views3 pages

CP Assignment2

Engeneering computer science assignment

Uploaded by

NAYAN Raj
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)
13 views3 pages

CP Assignment2

Engeneering computer science assignment

Uploaded by

NAYAN Raj
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/ 3

Jaypee University of Engineering and Technology, Guna

Computer Programming (CS101)

Assignment - 2

Submission Date: 05.11.2024

Total Marks: 10

Answer the following questions on blank loose papers (without lines) and submit to your
respective teaching faculty. It should be handwritten only.

1. Write a C program to find the equilibrium index of an array. An equilibrium index is an


index where the sum of elements on the left side of the index is equal to the sum of
elements on the right side.

Input:

● An integer N (the number of elements in the array).


● A sequence of N integers (the elements of the array).

Output:

● The first equilibrium index if it exists, or -1 if no such index exists.

2. A saddle point in a matrix is an element that is the smallest element in its row and the
largest element in its column. Write a C program to find the saddle point in a given
N×M matrix. If no saddle point exists, the program should output No saddle point
found.

Input:

● Two integers N and M representing the number of rows and columns in the
matrix, respectively.
● An N×M matrix of integers.

Output:

● The row and column number of the saddle point if it exists, or No saddle point
found if no such point exists.
3. Write a C program that repeatedly prompts the user to enter a number until a consecutive
prime sum is reached. A consecutive prime sum is a sum of consecutive prime numbers
starting from the smallest prime number (2) that equals or exceeds the entered number. If
the sum exceeds the number, the program should start again by prompting for a new
input.

Input:

● A single positive integer N entered by the user (greater than or equal to 2).

Output:

● Display the sum of consecutive prime numbers starting from 2 that equals the
entered number.
● If the sum exceeds the entered number, prompt the user to enter a new number
until a valid sum is achieved.

Example Input/Output:

Example 1:

Enter a number: 10

Consecutive prime sum: 10 (2 + 3 + 5)

Example 2:

Enter a number: 12

Sum exceeded the entered number. Try again.

Enter a number: 15

Sum exceeded the entered number. Try again.

Enter a number: 17

Consecutive prime sum: 17 (2 + 3 + 5 + 7)


4. Write a C program to print the following pattern using nested loop.

* *

* * * *

* * * * * *

* * * * * * * *

* * * * * * * * *

5. Design a program to manage and analyze student grades for multiple subjects. The
program will allow the user to input student data, calculate average grades, and determine
the highest and lowest grades in each subject.

Input:

● The number of students (S) and the number of subjects (M).


● The grades of each student for each subject.

Output:

● Display each student’s total and average grades.


● Display the highest and lowest grades for each subject, along with the
corresponding student indices.
● Display the average grades for each subject.

Requirements:

● Use 2D arrays to store the grades for each student and subject.
● Utilize loops for input, processing, and output.
● Ensure proper handling of student and subject limits.

You might also like