Nagoor PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

CSE101: Problem Solving & Programming in C – Question Bank

List of Programs
Index

Page
S. No Topic No.
I Introduction 2
II IF-Else and Switch 4
III Looping Constructs 5
IV Functions, storage classes and recursion 6
V Arrays 8
VI Strings 10
VII Pointers 10
VIII Dynamic Memory Allocation 11
IX Structures and Unions 12

1
CSE101: Problem Solving & Programming in C – Question Bank

I. Introduction
1. C "Hello, World!" Program
2. C Program to Print an Integer (Entered by the User)
3. C Program to Add Two Integers
4. C Program to Multiply two Floating Point Numbers
5. C Program to Find ASCII Value of a Character
6. C Program to Compute Quotient and Remainder
7. C Program to Find the Size of int, float, double and char
8. C Program to Demonstrate the Working of Keyword long
9. C Program to Swap Two Numbers
10. C program to subtract two long integers.
11. C program to calculate the distance between two points.
12. C program to perform addition, subtraction, division, integer division, multiplication
and modulo division on two integer numbers.
13. C program to demonstrate the use of printf and scanf statements to read and print
values of variables of different data types.
14. C program to display the substring “Good Mo” from the string “Good Morning” using
formatted printf statements and also do the left justification.
15. C program to display the character as in the following formatted way.
A
A
A
16. C program to calculate the area of a circle.
17. C program to read a character in uppercase and then print it in lower case.
18. C program to print the digit at tens place of a number.
19. C program to swap two numbers without using a temporary variable.
20. C program to convert degrees Fahrenheit into degrees Celsius.
21. C program to display the size of the every data types.
22. C program to calculate the total amount of money in the piggybank, given the coins
of Rs.10, Rs.5, Rs.2, Re.1.
23. C program to calculate the bill amount for an item given its quantity sold, value,
discount and tax.

2
CSE101: Problem Solving & Programming in C – Question Bank

24. Write a program to calculate a student’s result based on two examinations, one
sports event, and three activities conducted. The weightage of activities = 30%,
sports=20%, and examinations=50%.
25. C program to read an integer, then display the value of that integer in decimal, octal,
and hexadecimal notation.
26. C program that prints a floating point value in an exponential format with the
following specifications:
27. (a) Correct to two decimal places;
(b) Correct to four decimal places; and
(c) Correct to eight decimal places.
28. C program to read ten integers. Display these numbers by printing three numbers in
a line separated by commas.
29. C program to print the count of even numbers between 1 and 200. Also, print their
sum.
30. C program to read a floating point number. Display the rightmost digit of an integral
part of the number.
31. C program to calculate simple interest and compound interest.
32. C program to calculate salary of an employee, given his basic pay(to be entered by
the user), HRA=10% of the basic pay, TA=5% of basic pay, Define HRA and TA as
constants and use them to calculate the salary of the employee.
33. C program to prepare a grocery bill. Enter, the name of the item purchased, quantity
and its price per unit. Then display the bill in the following format.

********************BILL****************************
Item Quantity Price Amount
*****************************************************
____________________________________________________
Total Amount to be paid
_____________________________________________________

3
CSE101: Problem Solving & Programming in C – Question Bank

II. IF-Else and Switch


1. C program to find maximum between two / three numbers.
2. C program to check whether a number is negative, positive or zero.
3. C program to check whether a number is divisible by 5 and 11 or not.
4. C program to check whether a number is even or odd.
5. C program to check whether a year is a leap year or not.
6. C program to check whether a character is an alphabet or not.
7. C program to input any alphabet and check whether it is vowel or consonant.
8. C program to input any character and check whether it is an alphabet, digit or special
character.
9. C program to check whether a character is an uppercase or lowercase alphabet.
10. C program to input week number and print week day.
11. C program to input month number and print number of days in that month.
12. C program to input angles of a triangle and check whether the triangle is valid or not.
13. C program to input all sides of a triangle and check whether the triangle is valid or
not.
14. C program to check whether the triangle is an equilateral, isosceles or scalene
triangle.
15. C program to find all roots of a quadratic equation.
16. C program to calculate profit or loss.
17. C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics,
and Computer. Calculate percentage and grade according to the following:
Percentage>=90%: GradeA, Percentage>=80%: GradeB
Percentage>=70%:GradeC, Percentage>=60%:GradeD
Percentage>=40%:GradeE, Percentage < 40%:Grade F
18. C program to input the basic salary of an employee and calculate its Gross salary
according to the following:
Basic Salary <= 10000: HRA = 20%, DA = 80%
Basic Salary <= 20000: HRA = 25%, DA = 90%
Basic Salary >20000: HRA = 30%, DA = 95%
19. C program to input electricity unit charges and calculate total electricity bill
according to the given condition:
For the first 50 units Rs. 0.50/unit, For next 100 units Rs. 0.75/unit,
For next 100 units Rs. 1.20/unit, For unit above 250 Rs. 1.50/unit,
An additional surcharge of 20% is added to the bill
20. C program to print day of week name using a switch case.
21. C program to print a total number of days in a month using switch case.

4
CSE101: Problem Solving & Programming in C – Question Bank

22. C program to check whether an alphabet is a vowel or consonant using switch case.
23. C program to find maximum between two numbers using switch case.
24. C program to check whether a number is even or odd using switch case.
25. C program to check whether a number is positive, negative or zero using switch case.
26. C program to find roots of a quadratic equation using switch case.
27. C program to create Simple Calculator using switch case.

III. Looping Constructs


1. C Program to Display Characters from A to Z Using Loop
2. C Program to Count Number of Digits in an Integer
3. C Program to Reverse a Number
4. C Program to Find Factorial of a Number
5. C Program to Generate Multiplication Table
6. C Program to Display Fibonacci sequence
7. C Program to Calculate the Power of a Number
8. C Program to Check Whether a Number is Palindrome or Not
9. C Program to Check Whether a Number is Prime or Not
10. C Program to Display Prime Numbers Between Two Intervals
11. C Program to Check Armstrong Number
12. C Program to Display Armstrong Number Between Two Intervals
13. C Program to Display Factors of a Number
14. C Programming Code To Create Pyramid and Structure
15. C Program to Make a Simple Calculator Using switch...case
16. C Programming Code To Create Pyramid and Pattern
17. C program to print all natural numbers in reverse (from n to 1). - using while loop
18. C program to find the sum of all natural numbers between 1 to n.
19. C program to find the sum of all even numbers between 1 to n.
20. C program to print a multiplication table of any number.
21. C program to count the number of digits in a number.
22. C program to find the sum of first and last digit of a number.
23. C program to swap first and last digits of a number.
5
CSE101: Problem Solving & Programming in C – Question Bank

24. C program to calculate the product of digits of a number.


25. C program to check whether a number is a palindrome or not.
26. C program to find the frequency of each digit in a given integer.
27. C program to find all factors of a number.
28. C program to find HCF (GCD) of two numbers.
29. C program to find LCM of two numbers.
30. C program to print all Prime numbers between 1 to n.
31. C program to find the sum of all prime numbers between 1 to n.
32. C program to print all Armstrong numbers between 1 to n.
33. C program to print all Perfect numbers between 1 to n.
34. C program to print all Strong numbers between 1 to n.
34. C program to count a number of vowels in a text.
35. C program to find two's complement of a binary number.
36. C program to convert Binary to Octal number system.
37. C program to convert Binary to Decimal number system.
38. C program to convert Octal to Binary number system.
39. C program to convert Octal to Decimal number system.
40. C program to convert Decimal to Binary number system.
41. C program to convert Decimal to Octal number system.
42. C program to print Pascal triangle upto n rows.
43. C program to print the given star patterns.
44. C program to print the given number patterns.

IV. Functions, Storage Classes and Recursion


1. C program to read an integer number. Print the reverse of this number using
recursion.
2. C program to print Pascal triangle using recursion.
3. Create a function increment( ) and call it thrice in main(). In the function, declare a
variable of type integer, increment the variable and print the value. Exercise the
program with different storage classes ( auto, static, extern and register).
4. C program to perform linear search using function.
6
CSE101: Problem Solving & Programming in C – Question Bank

5. C program to perform linear search using recursion.


6. C program to convert octal to decimal and vice versa using function.
7. C Program to Find the Sum of Natural Numbers using Recursion
8. C Program to Convert Binary Number to Decimal and vice-versa
9. C Program to Convert Binary Number to Octal and vice-versa
10. C program to display prime numbers between two intervals using function.
11. C program to find the sum of natural numbers using recursion.
12. C program to test whether a given number can be expressed as a sum of two prime
numbers using function.
13. C program to calculate exp(x,y) using recursion.
14. C function to swap the value of two variables (int, float, double data-type), (pass value
as parameters),(call by value, call by reference).
15. C program using function to sum the series—1/1! + 1/2! + 1/3! + ….1/n!
16. C program to calculate GCD of two numbers using a recursive function.
17. C program to calculate the Factorial of a given number using a recursive function.
18. C program to generate Fibonacci series using a recursive function. (series 0 1 1 2 3 5
8…)
19. C program to implement the Tower of Hanoi problem using a recursive function.
20. C program using functions to calculate the area of a circle, triangle, different shapes
21. C function to evaluate f(x) = x - x3/3! + x5/5! …
22. C function to calculate parking charges of a vehicle. Enter the type of vehicle as
character (c- car, b- bus, t-two wheeler..etc) and number of parking hours then
calculate the charges as given: bus- 20 rupees per hour, car- 10 rupees per hour, two-
wheelers- 5 rupees per hour.
23. C functions to calculate Simple and Compound interest.
24. C Program to Display Prime Numbers between Intervals Using Function
25. C Program to Check Prime or Armstrong Number Using User-defined Function
26. C Program to Check Whether a Number can be expressed as Sum of Two Prime
Numbers
27. C program to Reverse a Sentence Using Recursion
28. C program to calculate the power using recursion

7
CSE101: Problem Solving & Programming in C – Question Bank

V. Arrays
1. C Program to Calculate Average Using Arrays
2. C Program to Find Largest Element of an Array
3. C Program to Calculate Standard Deviation
4. C program to convert Decimal to Hexadecimal number system
5. C program to convert Binary to Hexadecimal number system
6. C program to convert Octal to Hexadecimal number system
7. C program to convert Hexadecimal to Binary number system
8. C program to convert Hexadecimal to Octal number system
9. C program to convert Hexadecimal to Decimal number system
10. C Program to Add Two Matrix Using Multi-dimensional Arrays
11. C Program to Multiply to Matrix Using Multi-dimensional Arrays
12. C Program to Find Transpose of a Matrix
13. C Program to Multiply two Matrices by Passing Matrix to a Function
14. C Program to find the sum of all elements in an array
15. C program to read a sorted list of floating point values then calculate and display the
median of the values
16. C Program to sort the given array using bubble sort.
17. C Program to copy the contents of one array into another in the reverse order.
18. Twenty five numbers are entered from the keyboard into an array. Write a C Program
to find out how many of them are prime numbers.
19. C program to find whether the given element is present in an array or not using
Linear and Binary search.
20. C program to insert an element in a sorted array.
21. C program to arrange the values of an array in such a way that even numbers precede
the odd numbers.
22. Fill an array with positive and negative integers. Write a C program to separate
positive and negative numbers into two sub-arrays called “positive” and “negative”
and perform the following activities:
 Add two arrays
 Find the maximum and minimum of both arrays
 Find the size of both arrays and print the array name which has more elements

8
CSE101: Problem Solving & Programming in C – Question Bank

23. C program to get the array size and contiguous numbers as an input (for example 1 2
3 5 6). Find a missing number and its position.
24. C program to find the number of non repeated numbers in an array and print the
numbers and their count (ex:12233345…. Ans: count is 3, and the numbers are 1 4 5)
25. C program to find the sum of diagonal elements in a given matrix.
26. C program to check whether the given matrix is symmetric or skew Symmetric
27. program to find the sum of upper triangular and lower triangular of the square
matrix.
28. Menu driven C program to add, subtract and multiply the contents of two given
matrices.
29. C program to count the total number of non-zero elements in a two-dimensional
array.
30. C program to pick up the largest number from any m X n matrix.
31. Consider an array MARKS[5][20] which stores the marks obtained by 20 students in 5
subjects. Write a program to do the following operations.
32. Find the average marks obtained by every student
33. Find the average marks obtained by each subject
34. Find the number of students who have scored below 50 in their average.
35. Display the records by every student.
36. Write a program to store one-dimensional array values into a two-dimensional array.
37. A magic square is a square array of positive integers such that the sum of each row,
column and diagonal is the same constant. For Example, the below square is a magic
square whose constant is 34.

38. 16 39. 3 40. 2 41. 13


42. 5 43. 10 44. 11 45. 8
46. 9 47. 6 48. 7 49. 12
50. 4 51. 15 52. 14 53. 1

Write a c program to determine whether or not the given square is a magic square.

9
CSE101: Problem Solving & Programming in C – Question Bank

VI. Strings
1. C program to illustrate how to read a string from the terminal.
2. C program to read a line of text using gets() and puts()
3. C program to read a line of text character by character.
4. C Program to Find the Frequency of Characters in a String
5. C program to count the number of vowels, consonants and so on
6. C Program to Remove all Characters in a String Except Alphabet
7. C Program to Find the Length of a String
8. C Program to Check the given string is Palindrome or not
9. C Program to Insert a substring
10. C Program to Concatenate Two Strings
11. C Program to Copy String Without Using strcpy()
12. C Program to Sort Elements in Lexicographical Order (Dictionary Order)
13. C program passing Strings to a function
14. C program to Swap the Strings
15. C program to reverse words in a line
16. C Program to reverse a line
17. C program to find a maximum occurrence of a character in the string
18. C program to find the lowest frequency character in the string
19. C program to remove extra spaces from a string
20. C Program to Display every possible Combination of two Words or Strings from the
input Strings without Repeated Combinations

VII. Pointers
1. C Program to Access Elements of an Array Using Pointer
2. C Program Swap Numbers in Cyclic Order Using Call by Reference
3. C Program to sort an array of elements using pointers (bubble sort, selection sort, etc)
4. C Program to store a set of strings in an array. Access the strings and sort them using an
array of pointers.
5. C Program to reverse the elements of an array using pointers.

10
CSE101: Problem Solving & Programming in C – Question Bank

6. C Program to compare two strings using pointers.


7. C Program to return more than one value from a function using pointers.
8. Write a function that receives 3 arguments – an array of numbers, 2 variables – small
and large. The function finds the largest and the smallest element in the array and
stores them in the corresponding variables passed as arguments. Call this function from
the main program by passing all the arguments by pointer and print the result in the
main program. Do not return any values from the function back to the calling program.
9. Using pointers, write a function that receives a character string and a character as
argument and deletes all occurrences of the character in the string. The function should
return the corrected string with no holes. Write main program to test the above
function.
10. C program to print all permutations of a given string using pointers.
11. C Program to sort the characters in the given string by accessing the individual
characters by pointers.
12. C program to accept an array of elements as input (numeric or character). Pass this
array by pointer to a function. Inside the function, exchange the first character with last
character, second with last but one and so on. Print the elements of the array after
exchange in the main program.

VIII. Dynamic Memory Allocation


1. C Program to Find Largest Number Using Dynamic Memory Allocation
2. C program to read and display the values of a character array.
3. C program to multiply two matrices.
4. C program to get the list of strings as input and display the names after sorting it
without using arrays.
5. C program to get an unsorted integer array as input and sort the array. In the sorted
array, swap the largest and smallest number.
Example: Input: 58, 63,1, 25, 29 Sorted: 1, 25, 29, 58, 63 Swapped: 63, 25, 29, 58, 1
6. C program to merge two sorted arrays. The resulting array should be in sorted order.
7. C program to get two matrices as input. The values of the matrix range from 10 to 20.
Add the two matrices and in the resultant matrix, replace the values below 15 with
zero.
8. C program to merge two floating point arrays and display the merged array in reverse
order.

11
CSE101: Problem Solving & Programming in C – Question Bank

9. C program to read a character array. Update the array to insert a new character at a
specified position.
10. C program to read the marks of 5 students in 3 subjects and display the highest marks
in each subject.
11. C program to that reads a matrix and displays the sum of the elements above the main
diagonal.

IX. Structures and Unions

1. Program using a function to perform addition subtraction and multiplication of two


complex numbers and print in the complex number format (a + bi, taking care of
negative values for a and b ) using structures
2. Program to perform addition and subtraction of two given polynomials of orders m and
n using structures
3. Program to perform addition and subtraction of two given distances (in kms and mtrs)
using structures. Take care of all the conditions.
4. Program to repeatedly find the difference between heights of two persons given in feet
and inches stored as structures until the user chooses to stop. The program must take
care of input validation and other conditions. (E.g. if an inch is greater than 12 change it
to feet).
5. Program to find the difference between two given times using structures. Take care of
all the conditions
6. Program to read, print and find the validity of the given date using a structure for date.
For example 31.11.2011, 29.02.2009, 01.13.2015 are invalid dates
7. Program which uses a function to find the distance between two coordinates in a 3
dimensional plane using structures
8. Program which uses a function to find whether the given 3 points in the form of (x, y)
are on a straight line or not using structures.
9. Create a structure named student with rollno, name and grade as members. The
number of records to be kept is given by the user and an array of objects for the
structure is created. Implement the functions (i) Create records (ii) Search a particular
record by rollno and name (iii) display fun (iv) exit. Implement the same as menu
driven.
10. Implement the above program with a different set of functions as (i) Sort by name(ii)
Sort by roll no (iii) Sort by Grade. Implement the same as menu driven program.

12
CSE101: Problem Solving & Programming in C – Question Bank

11. Create a structure named student with rollno, name, mark1, mark2, mark3, mark4 and
mark5 as members. Find the average with the given marks for n number of students by
creating an array of objects for the structures and sort the records based on average
and display it.
12. Implement the 11th exercise and add one more member called attempts the functions(i)
Count the no of failures in each subject (ii) no of students who got above 80. (iii) If he is
not failed and no of attempts is less than 1 in for each subject then based upon the
average print whether he is eligible for attending interviews.
13. Write a program to compare the size of structures and unions with the same data
members inside. E.g., int age, char name[20], double salary, float PF. Print the size of
structure and union.
14. Create an employee structure with members empno, name,basicpay, allowance,
deductions, and netpay .calculate the netpay of the employee.

E.g Netpay = basicpay + allowance-deductions. Create an array of structure objects and


print the netpay for every employee.

15. Repeat the 13th question by finding the person with maximum pay and minimum pay.

16. Create a structure which stores the birth date (dd, mm, yy, and name) of the person.
Create two structure objects , compare and print who is elder ?

17. Create a structure called library which contains the below information
Struct library {
No.of books;
No.of E-Journals;
No of Magazines;
No of E-books; }

Implement the functions such as (i) Maximum Volume (i) Minimum volume or least
books. based on the total volumes (iii) Display (iv) Sort by maximum volumes

18. Create a structure with members x and y of type int create a structure object and a
pointer to a structure. Now pass the address of the structure object to the pointer
object. Get inputs for x and y from the user and compare x and y print which is
greater.

19. Create a structure called address with houseno, city, pincode as members and create
another structure employee with id, name, salary and create structure object for
address in employee structure. Implement the functions (i) getdetails(ii) display
(iii)exit.

13
CSE101: Problem Solving & Programming in C – Question Bank

20. Implement a Bank management application as menu driven program. First, it should
display the options (i) operation (ii) display (iii)exit. If the user presses the option one,
operation is chosen it moves to another menu driven by listing (i) Withdrawal (ii)
Balance Enquiry (iii) Deposit as separate functions. Create a structure called Bank with
account holder name, Accno, expiry date, Branch as members. If the user chooses a
deposit, the deposited amount should be reflected if the display function is called.
Similarly for other functions also.

21. Create a structure student with data members fname, lname, id, age, semester. Create
an array of three objects, and after assigning it to a pointer object implement the
functions getdata() and display().

14

You might also like