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

Computer Programming Exercises and Solutions

Uploaded by

krsujal66
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)
15 views3 pages

Computer Programming Exercises and Solutions

Uploaded by

krsujal66
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

Computer project

Question 1

Write a program to accept roll numbers and the marks secured in computer application by
40 student of a class in two single dimension arrayy. Sort this mark in descending order
and corresponding roll numbers. Finally display the role number and the marks of each
students in sorted order side by side.

Question 2

Write a program to accept 20 numbers in a single dimensional array array[20] . Transfer and
store all the even number in an array even and all the odd numbers in another array odd.
Finally print the elements of both arrays.

Question 3

A metropolitan hotel has five floors and 10 rooms in each floor. The name of the visitors are
entered in a double dimensional array as M [5][10]. The hotel manager want to know from
the enquiry about the position of a visitor ( i.e floor number and room number) as soon as
he enter the name of the visitor. Write a program to perform the above task.

Question 4

Given below are two arrays-

A[5]= {1, -3, -6, 8, 13};

B[5]={0,3,18,21,17};

Write a program that combines both the arrays into another array C and produce the output
as follows-

C[10]={1,0,-3,3,-6,18,8,21,12,17};

Question 5

Write a program to input 10 words in an array. Arrange the name in alphabetical order
using Selection sort

Question 6

Write a program to input N number of numbers in a integer array and exchange the value
of the first half with the second half of the array . Program should print the elements of the
array after exchange.

Question 7
Write a program to print the sum of negative numbers, sum of positive even numbers and
sum of positive odd numbers from a list of numbers (N) entered by the User .

Question 8

Write a program that outputs the results of the following evaluations based on the number
entered by the user.

(i) Natural logarithm of the number

(ii) Absolute value of the number

(iii) Square root of the number

(iv) Random numbers between 0 and 1.

Question 9

Using a switch statement, write a menu driven program to convert a given temperature
from Fahrenheit to Celsius and vice versa. For an incorrect choice, an appropriate error
message should be displayed.

(HINT: C = 5/9x (F-32) and F = 1.8 x (C+32)

Question 10

Write a program to calculate and print the sum of each of the following series:

(a) Sum (S) = 2 – 4 + 6 – 8 + - - - - 20

(b ) Sun (S) =x/ 2 + x/5 + x/8 + x/11 + x/14 + x/17 + x/ 20

(Value of x to be input by the user).

Question 11

Write a menu driven program to accept a number and check and display whether it is a
prime number or not OR an automorphic number or not. (Use switch- case statement)

(a) Prime number: a number is said to be a prime number if it is divisible only by 1 and itself
and not by any other number.

Example: 3, 5, 7, 11, 13 etc.,

(b) Automorphic number: An automorphic number is the number which is contained in the
last digit(s) of its square.
Example 25 is an automorphic number as its square is

625 and 25 is present as the last two digits.

Question 12

The annual examination results of 50 students in a class is tabulated as follows:

Roll No. Sub.A Sub.B Sub.C

---------- -------- ------- -------

_ _ _ _

_ _ _ _

_ _ _ _

Write a program to read the data, calculate and display the following:

(a) Average marks obtained by each student.

(b) Print the roll number and average marks of the students whose average mark is above
80.

Common questions

Powered by AI

To determine if a number is automorphic, compute its square and compare the square's last digits to the original number's digits. In a program, convert both the number and its square to strings, and check if the string of the square ends with the string representation of the number. This logic utilizes the properties of string manipulation for effective comparison .

Selection Sort is effective for ordering words alphabetically because it repeatedly selects the smallest (or largest, depending on order) element from the unsorted portion and moves it to the sorted portion. In implementation, the array of words is iterated through, selecting the lexicographically smallest word in each pass and swapping it with the current position, resulting in an alphabetically sorted list .

To implement a hotel management system that identifies a visitor's room, use a two-dimensional array where each row represents a floor, and each column represents a room number. When a visitor's name is entered, a loop through the array allows you to find the entry, retrieve the index of the row (floor), and the column (room number) to determine and display the visitor's location within the hotel .

A program for Fahrenheit to Celsius conversion using a switch statement can be structured by first prompting the user for their temperature conversion choice. The switch statement corresponds to each case (e.g., convert to Celsius or convert to Fahrenheit), applying the appropriate conversion formula: C = 5/9 * (F - 32) for Fahrenheit to Celsius, or F = 1.8 * C + 32 for Celsius to Fahrenheit. Include a default case for erroneous input .

To efficiently sort student marks and roll numbers in descending order, you can utilize a sorting algorithm such as Bubble Sort or Selection Sort. First, store the marks and corresponding roll numbers in parallel arrays. Apply the sorting algorithm to the marks while simultaneously swapping the roll numbers to maintain their link with the marks. Finally, iterate through the sorted arrays and print each roll number with its corresponding mark .

To segregate even and odd numbers from a given array, traverse the array while checking the modulus of each number. If the number is divisible by 2, append it to the 'even' array; otherwise, append it to the 'odd' array. This separation allows for an ordered collection of even and odd numbers .

To rearrange a series of numbers by inverting the first and second halves, first determine the midpoint of the array. Then swap elements from the first half with the corresponding elements from the second half, iterating up to the midpoint. This technique effectively reverses the order of the two halves without changing each half's internal sequence .

To calculate sums for negative numbers, positive even numbers, and positive odd numbers in a list, iterate through each number in the list. Use conditional statements to identify the type of each number: add to a negative sum if the number is negative, to the positive even sum if it is positive and even, and to the positive odd sum if it is positive and odd. Summing these individually provides the desired totals .

A two-dimensional array efficiently organizes examination scores by tabulating each student's marks across multiple subjects, where each row corresponds to a student's scores. Calculating averages per student involves iterating through their row entries, and specific scores can be quickly accessed through indexed traversal, facilitating both data retrieval and calculation tasks .

To calculate the position of a visitor in a hotel represented by a two-dimensional array, each floor and room is indexed. When a visitor's name is entered, search the array to match the name, which will yield the array indices corresponding to the floor and room. This setup effectively maps each array index to a real-world location in the hotel .

You might also like