[go: up one dir, main page]

0% found this document useful (0 votes)
22 views9 pages

CP Practice Questions

Uploaded by

Nuha
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)
22 views9 pages

CP Practice Questions

Uploaded by

Nuha
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/ 9

C programs

1. Write a C program to show the use of all operators


2. Write a C program to find the maximum of 3 numbers using ternary operators
3. Write a C program to enter a list of integer numbers till user enters any negative value. Calculate
the sum for only odd numbers amongst them and display the same. Also display the count of
odd numbers.
4. Write a C program to read the value of x and evaluate the following function Y=1 for x>0 Y=0
for x=0 Y=-1 for x<0. Use nested if condition
5. Write a menu driven program to print ‘*’ for following operation:
a. Whole screen
b. Half screen
c. Top 3 lines
d. Bottom 3 lines
6. Write a C program to find the number of and sum of all integers greater than 100
And less than 200 that are divisible by 7. Using do-while condition.
7. Write a c program to merge two sortd arrays.
8. Write a C program to insert and delete an element into an array. Write a menu driven program.
9. Write a C program to print the elements from the array which are divisible by 3 and 5.
10. Write a menu driven program to find the sum of each row each column and grand sum of
matrix.
11. Write a C program to count positive ,negative and non zero element using function.
12. Write a C program that fills 5X5 matrix—
A} upper left triangle with +1.
B) lower right triangle with -1.
c) Diagonal element with 0.

13. write a program to display pattern.


14. write C program to sort a string in alphabetic order: For example if user will enter a string
"programming" then output will be "aggimmnoprr" or output string will contain characters in
alphabetical order.
15. write a C program to sort a strings using 2D array.
16. write a C program to sort integer array using Bubble sort using function .
17. write a C program to remove duplicate elements from array using function.
18. write a C program to shift array element in right by one position.for ex. Input [1 2 3 4] ,
Output [4 1 2 3] using function.
19. write a C program to add two complex numbers using structure and function.
20. write a C program to add, subtract and multiply two matrices using function.
21 .write a C program to create a pointer to integer accept the values using a pointer to form a list of n
elements and display second largest elements and second smallest element amongs them using
malloc and free.
22.write a C program to define a structure called Rational . create pointer to the same to add and
multiply two rational numbers.wrtie function definitions for same.
23.write a C program to create structure called British with feet and inch as the contents also define
structure called Metric with meter and centimeter as the content . Add these two distance values
and display the result either in feet-inch or m-cm.
24 write a C program to define Employee structure having fields as employee code, employee name,
salary and Date of joining. Define structure for Date of Joining.Sort employee records based on highest
salary.
25. Write a C program to define a structure Cricketer having field like cricketer name, no.of matches
played, score .
26.write a C program to find sum of array elements.End of an array must get terminated by 9999.

27.write a C program to check string is palindrome or not and count the character frequency using
function.
28.write a C program to swap strings without using string function.

If - Else Problem statement:

1. Write a C program to find maximum and minimum no. out of 2 nos.


2. Write a C program to check number is positive, negative or zero.
3. Write a C program to check the number is odd or even.
4. Write a C program to check divisibility of n/d.
5. Write a C program to check the number is divisible by 10 or not.
6. Write a C program to check the number is in multiple of 7 or not.
7. Write a C program to check the accepted triangle sides are forming the valid triangle or not.
8. Write a C program to check the accepted triangle sides are forming the right angled triangle or
not.
9. Write a C program to check the accepted number is ending with 4 or not.
10. Write a C program to calculate area of circle and rectangle based on accepted value of character
c.
11. Write a C program to calculate roots and find the type of roots of quadratic equations.
12. Write a C program to find the maximum number out of 3 numbers.
13. Write a C program to check the accepted character is vowel or not.
14. Write a C program to whether entered number is two digit +ve number or not.
15. Write a C program to check the number is divisible by 5 or 7 or both.
16. Write C program to check the accepted character is lower case letter, upper case letter, number
or special symbol.
17. Write a C program to that will read the value of x and evaluate the following function
Y=1 for x>0
Y=0 for x=0
Y=-1 for x<0

Use nested if.


18. Write a C program to display the interest earned based on type of account. There are 6 different
types of accounts and they earn interest as follows.

19. Account Type 20. Interest Earned


21. 1. Personal 22. 2.3%
financial
23. 2.Personal 24. 2.6%
homeowner
25. 3.Personal gold 26. 2.9%
27. 4.Small business 28. 3.3%
29. 5.Big business 30. 3.5%
31. 6 Gold business 32. 3.8%

20. Write a C program to display spelling of a accepted single digit number.

(Ex: if single digit 1 is accepted then output will be –One)

21. Write a C program to display month name for a accepted month number.

(Ex: if single digit 1 is accepted then output will be –January)

22. Write a C program to find the minimum number out of 3 numbers.

23. Write a C program to implement a simple calculator (+, - , /, % mod) . Accept two numbers and
accept one char. input (Arithmetic symbol). Based on accepted char input program must perform the
operation.

24. Write a C program that will read the values of a, b, c, d, m and n and compute the values of x1 and
x2. An appropriate message should be printed if ab-cd=0.

A set of linear equations with two unknowns x1 and x2 is given below:

ax1+bx2=m and cx1+dx2=n

The set has a unique solution:

x1=(md-bn) / (ad-cb) x2=(na-mc) / (ad-cb)

Provided the denominator ad-cb is not equal to zero.

25. Write a C program to read empid , no.of hours,,rate per hour and calculate pay and tax (based on
pay) as if pay<300 give 15% of the pay otherwise 28% of the pay.Also calculate netpay =pay-tax.
26. Write a C program to accept custtno, units as integer consumed by customer and calculate charges
as float based on accepted units .

Unit<=200 charges=50% of units


Unit<=400 charges=65% of units
Unit<=600 charges=80% of units.
26. Write a C program to assign and display grade based on accepted grade:

Score=100 Grade= A+
Score>=90 Grade=A
Score>=80 Grade=B
Score>=70 Grade=C
Score>=60 Grade=D
Otherwise Grade=F

Nested for loops:

1. Write a program to display prime numbers upto n numbers.

Write a program to display the following pattern:

2.
1
11
111
1 1 1 1 upto n lines

3.
1
12
123
1234
12345

4.
1
22
333
4444
55555

5.
1
212
32121
4321321
6.
1
21A
321BA
4321CBA
54321DCBA
7.
*
**
***
****
8.
A
ABA
ABCBA
ABCDCBA
9.
****
***
**
*
10.

A
BC
DEF
GHIJ
Accept number of lines
11.
1
22
333
4444
55555

12.
1
121
12321
1234321

13.
P
PQ
PQR
PQRST

14.
*

**

***

****

15.
*
**
***
****
***
**
*
16.
*
**
***
****
***
**
*

17.
*****
****
***
**
*
18.
ABCDCBA
ABCBA
ABA
A

19.

1
121
12321
1234321
121
1

20.
5
54
543
5432
54321

21.
54321
5432
543
54
5

While and do-while loop

Write following C programs using while and do while loop:

1. To calculate sum of 1st even nos.


2. To print all odd numbers < n.
3. To print 1st n odd numbers.
4. Program to find the following sum:
1+3+5+7+….till 100
5.
To calculate t = x y ( x raise to y)
6. To calculate the following sum=

S= (2/3) + (4/5) + (6/7)+…………… +n terms


7. To calculate factorial of number no. (Check if number is 0 then it should display factorial of n)
8. To calculate sum of 1st odd nos
9. To find the number of and sum of all integers greater than 100 and less than 200 that are
divisible by 7.
10. To compute and display the sum of all integers divisible by 6 and not divisible by 4 and lie
between 0 to100 count also and print number of such values.
11. To calculate GCD of 2 numbers.
12. To calculate sum of every third integer till (i=2 to 100)
2+3+5+……….. up to 100
13. To print Fibonacci series up to n terms.
14. To calculate the following sum=
S=1- (1/2) + (1/3) – (1/4) +…………… n terms
15. To reverse the number (if n=1234 , reverse of a number 4321)
16. To check the number is Armstrong number or not (153=1 3+53+33)
17. To print all even numbers < n.
18. To calculate the following series
S = 1+ x2 +x3+x4+ …………..+n terms
19. To calculate LCM of 2 numbers without using GCD.
20. To find the sum of all odd integers up to 100 which are not divisible by 5.
21. All integers converges to 1 if subjected to following steps,
i. If it is odd, multiply by 3 and add 1
ii. If it is even, divide it by 2
iii. Repeat the above steps still it converges to one.
22. Program to print intermediate values and also count the number of iterations required for
convergence.
23. Program to check whether entered number is prime or not.
24. Program to find the 5 digit number which on multiplication by 4, reverses its order.
25. Program to compute following series:
x/1! + x 2 /2! + x 3/3! + …. up to 20 terms
26. Program to print all even numbers up to 200 which are not divisible by 6 and 8 up to 50
27. Program to calculate squares and cubes of first 10 numbers.
28. Program to display first 10 even numbers and their squares.
29. Program to print all multiples of 3 from 3 to 36.
30. Program to determine the sum of the following harmonic series for a given value of n:
1+1/2+1/3+…………1/n
31. Program to find number of and sum of all integers greater than 200 and less than 350 that are
divisible by 9.
32. Program to find the following sum:
2+4+6+8+….till 100

32. Program to that will allow the user to input ten scores in order to find the average of the scores.

33. Program to print all 2 digit perfect squares.

34. Program to which reads an integer N followed by N numbers, prints each number and sum of
numbers read so far.

You might also like