0% found this document useful (0 votes)
75 views

Problem Analysis Using Operators With Flow-Charts: Practice Problems

The document contains practice problems for analyzing problems and writing C programs using various programming concepts like operators, conditionals, loops, arrays, strings, and functions. It includes 18 problems on operators, 15 problems on conditionals, 15 problems on loops, 15 problems on arrays, 10 problems on strings, and 4 problems on functions. It provides reference to relevant chapters and sections in the book "Programming in ANSI C" by E. Balagurusamy for further reading.

Uploaded by

PremiumHut
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)
75 views

Problem Analysis Using Operators With Flow-Charts: Practice Problems

The document contains practice problems for analyzing problems and writing C programs using various programming concepts like operators, conditionals, loops, arrays, strings, and functions. It includes 18 problems on operators, 15 problems on conditionals, 15 problems on loops, 15 problems on arrays, 10 problems on strings, and 4 problems on functions. It provides reference to relevant chapters and sections in the book "Programming in ANSI C" by E. Balagurusamy for further reading.

Uploaded by

PremiumHut
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/ 8

Practice Problems

Problem Analysis using Operators with Flow-charts


1. Write a c program to calculate the sum of two numbers.
2. Write a c program to calculate the average of three numbers.
3. Write a c program to calculate the area of a triangle using 1/2 * base * height.
4. Write a c program to calculate the area of a triangle using three sides.
5. Write a c program to calculate the area of a rectangle.
6. Write a c program to calculate the area of a circle.
7. Write a c program to convert Celsius temperature to Fahrenheit temperature.
8. Write a c program to convert Fahrenheit temperature to Celsius temperature.
9. Write a c program to swap two numbers.
10. Write a c program to ceil, round, and floor a floating point number.

Reference Book: Programming in ANSI C, Balagurusamy (4th Edition)


● Chapter 1: Overview of C
○ Exercises: 1.11, 1.12, 1.13, 1.15
● Chapter 3: Operators and Expressions
○ Case Studies: 1, 2
○ Exercises: 3.1, 3.2, 3.3, 3.6, 3.7, 3.9, 3.11, 3.13, 3.14, 3.15, 3.16, 3.19

1 of 8
Practice Problems

Problem Analysis using Conditionals with Flow-charts


1. How does the if-else statement work?
2. Write a c program to check whether a number is even or odd.
3. Write a c program to check whether a number is positive or negative or equal to zero.
4. Write a c program to find the largest between two numbers.
5. Write a c program to find the smallest among three numbers.
6. Write a c program to check whether a year is a leap year or not.
7. Write a c program to check whether a student has passed (40%) or failed from a given
mark.
8. Write a c program to calculate the grade points of a student for a particular subject from
the given mark using the following table:
90% and 80% to below 70% to below 60% to below 50% to below
Below 50%
above 90% 80% 70% 60%
4.0 3.5 3.0 2.5 2.0 0
9. Write a c program to check whether a character is a capital letter or a small letter or
others.
10. Write a c program to check whether a character is a vowel or consonant or digit or white
space or special character.
11. How does the switch statement work?
12. Write a c program to spell a digit using switch.
13. Write a c program to check whether a character is vowel or consonant using switch.
14. Write a c program to implement a calculator (+, -, *, /, %) using switch.
15. Write a c program to implement a menu based temperature conversion using switch.

Reference Book: Programming in ANSI C, Balagurusamy (4th Edition)


● Chapter 5: Decision Making and Branching
○ Examples: 5.5, 5.6, 5.7
○ Case Studies: 1, 2
○ Exercises: 5.1, 5.2, 5.3, 5.4, 5.5, 5.8, 5.9, 5.10, 5.11, 5.12, 5.13, 5.15

2 of 8
Practice Problems

Problem Analysis using Loops with Flow-charts


1. How does loop work?
2. Write a c program to print the sum of the following series:
a. 1 + 2 + 3 + . . . . + N
b. 12 + 32 + 52 + . . . . + N 2
c. 22 * 42 * 62 * . . . . * N 2
1 1 1
d. 1 + 2
+ 3
+ .... + N

e. 1 − 2 + 3 − 4 + 5 − 6 + . . . . + N
f. 1 * 2 + 2 * 3 + 3 * 4 + . . . . + n1 * n2
g. 1 * 3 * 4 + 2 * 5 * 6 + 3 * 7 * 8 + . . . . + n1 * n2 * n3
h. 1 + 5 + 9 + . . . . + N th number
i. 1 + 2 + 4 + 5 + 7 + 8 + .... + N
j. 60 + 57 + 54 + . . . . ≥ 1
3. Write a c program to calculate the sum of the Fibonacci series upto N-th term:
0 + 1 + 1 + 2 + 3 + 5 + 8 + . . . . + N th term
4. Write a c program to calculate the factorial of a number.
5. Write a c program to calculate the GCD and LCM of two numbers.
6. Write a c program to check whether a number is prime or not.
7. Write a c program to print the prime numbers within a range.
8. Write a c program to count the number of digits of a number.
9. Write a c program to calculate the sum of digits of a number.
10. Write a c program to reverse a number.
11. Write a c program to check whether a number is a palindrome or not.
12. Write a c program to print the palindrome numbers within a range.
13. Write a c program to check whether a number is an Armstrong number or not.
14. Write a c program to print the Armstrong numbers within a range.
15. Write a c program to check whether a number is a Strong number or not.

3 of 8
Practice Problems

16. Write a c program to print the following pattern:


(a) 1 (b) 1 (c) A (d) *
12 00 BB **
123 111 CCC ***

(e) 3 3 3 (f) 1 0 1 (g) a b c (h) # # #


22 10 ab ##
1 1 a #

17. Write a c program to print the following pattern:


(a) 1 (b) 1 (c) 1 (d) 1
12 22 2 4 2 3
123 333 3 6 9 4 5 6
12 22 4 8 16 20 7 8 9 10
1 1

18. Write a c program to print the following pattern:


(a) * * * (b) * (c) * *
* * ** * *
* * * * *
* * * * * *
* * * **** * *

Reference Book: Programming in ANSI C, Balagurusamy (4th Edition)


● Chapter 6: Decision Making and Looping
○ Examples: 6.2
○ Case Studies: 3
○ Exercises: 6.1, 6.2, 6.3, 6.4, 6.6, 6.7, 6.11, 6.15, 6.18

4 of 8
Practice Problems

Problem Analysis using Arrays


1. Write a c program to calculate the sum and average of an array.
2. Write a c program to find both values and indexes of maximum and minimum elements
of an array.
3. Write a c program to search a number in an array. It will print the index of the element, if
it is found. Otherwise, it will print “Not found.”
4. Write a c program to count the frequency of a number in an array.
5. Write a c program to copy an array to another array.
6. Write a c program to reverse an array.
7. Write a c program to sort an array.
8. Write a c program to calculate the sum and average of a 2D array.
9. Write a c program to find both values and indexes of maximum and minimum elements
of a 2D array.
10. Write a c program to calculate the sum of diagonal elements of a matrix.
11. Write a c program to add two matrices. If A and B are two matrices, the sum of these
matrices, C = A + B.
12. Write a c program to subtract two matrices. If A and B are two matrices, the difference of
these matrices, C = A - B.
13. Write a c program to multiply a matrix by a factor.
14. Write a c program to multiply two matrices. If A and B are two matrices, the product of
these matrices, C = A * B. Given, A={{1, 2}, {1, 2}} and B = {{2, 1}, {2, 1}}.
15. Write a c program to transpose a matrix, i.e., A’. Given, A = {{1, 2}, {2, 4}}.

5 of 8
Practice Problems

Problem Analysis using Strings


1. Write a c program to search for a character in a string. It will print the index of the
element, if it is found. Otherwise, it will print “Not found.”
2. Write a c program to count the frequency of a character in a string.
3. Write a c program to count the number of capital letters and small letters in a string.
4. Write a c program to count the number of vowels, consonants, digits, white-spaces, and
special characters.
5. Write a c program to count alphanumeric characters in a string. Note that alphanumeric
characters are a combination of alphabetic and numeric characters. Your program will
print 8 for this string "<html></html>".
6. Write a c program to calculate the length of a string.
7. Write a c program to add three strings.
8. Write a c program to copy a string to another string.
9. Write a c program to reverse a string.
10. Write a c program to check whether a string is a palindrome or not.

6 of 8
Practice Problems

Problem Analysis using Functions


1. How does function work?
2. Write a c function that takes two numbers as parameters and returns the sum of them.
3. Write a c function that takes a year as a parameter and returns 1 if it is a leap year,
otherwise, it returns 0. It will return 1 for 2000 and 0 for 2100.
4. Write a c function that takes mark of a subject as parameter and returns obtained grade
using the following table:
90% and 80% to below 70% to below 60% to below 50% to below
Below 50%
above 90% 80% 70% 60%
4.0 3.5 3.0 2.5 2.0 0
5. Write a c function that takes a number as a parameter and returns 1 if it is prime,
otherwise, it returns 0. It prints 1 for 23 and 0 for 22.
6. Write a c function that takes an array as a parameter and returns the average of that array.
7. Write a c function to check whether a string is a palindrome or not. It returns 1 if given
string is a palindrome, otherwise, it returns 0. A string is called palindrome if the reverse
of the string is the same as the original string, i.e., madam. You can use library functions.
8. Write a c function to calculate the factorial of a number using recursion.
9. Write a c function to calculate the sum of the multiples of 7 within 1 to 100, i.e.,
7+14+21+...+98, using recursion. It will print 735.
10. Write a c function to swap two numbers using pointer.

7 of 8
Practice Problems

Problem Analysis using Structures


1. What is a structure?
2. Write a c program to calculate the slope of the line that goes through the two points P​1
(x​1​, y​1​) and P​2 (x​
​ 2​, y​2​) using structure. Given, slope
Δy y2 − y1
m = Δx
= x2 − x1

8 of 8

You might also like