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

OODP Week 2 Exercises

The document outlines a series of C++ and C programming exercises focused on control structures, arrays, strings, functions, structures, unions, and file handling. Each exercise includes specific tasks such as determining if a number is positive or negative, calculating sums, finding prime numbers, and manipulating strings and arrays. Additionally, it covers file operations including reading, writing, and modifying file contents.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

OODP Week 2 Exercises

The document outlines a series of C++ and C programming exercises focused on control structures, arrays, strings, functions, structures, unions, and file handling. Each exercise includes specific tasks such as determining if a number is positive or negative, calculating sums, finding prime numbers, and manipulating strings and arrays. Additionally, it covers file operations including reading, writing, and modifying file contents.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ Lab 2 Exercises

Topics : Control Structures Prepared by Dr. G. Malarselvi / CTECH

1. Write a C++ program to print whether the given number is positive


number or negative number.
2. Write C++ program to find if an integer is positive, negative or zero //
using nested if statements
3. Write a program to checks whether a year (integer) entered by the user is a
leap year or not. Using if...else Ladder
4. Write C++ program to find the sum of positive numbers, if the user enters
a negative numbers, break ends the loop the negative number entered is not
added to sum.
5. C++ Program to Count Total Number of Notes Using If Else Statement.

Example Test case:

Input: Enter the amount: 5454


Output:
Total number of notes:
2000 = 2
500 = 2
200 = 2
100 = 0
50 = 1
20 = 0
10 = 0
5=0
2=2
1=0

6. Write a program to find the prime numbers between100 to 500.


7. Write a program to calculate positive numbers till 50 only if the user enters
a negative number, that number is skipped from the calculation. (negative
number -> loop terminate , numbers above 50 -> skip iteration)
8. Consider the situation when you need to write a c++ program which
prints number from 1 to 10 and but not 6. It is specified that you have to
do this using loop and only one loop is allowed to use.
9. Write a program to create a Calculator using the switch Statement.
10. Write a program to calculate the average of numbers entered by the user. If
the user enters a negative number, it ignores the number and calculates the
average number entered before it (Use Go to statement)
11. Write C++ program to check if a number is even or not using go to
statement
12. Write a program to find factorial of a given number using Recursion
13. Write a program to find Fibonacci series Using Recursion in C++.
14. Write a program to Calculate Number Power Using Recursion in C++.
15. Write a program to find Reverse a number Using Recursion in C++.
Arrays, Strings and Functions prepared by Dr. V Joseph Raymond /NWC
1. Write a C++ program to find the largest element of a given array of integers
2. Write a C++ program to rearrange the elements of a given array of integers in
zig-zag fashion way.
3. Write a C++ program to find and print all common elements in three sorted
arrays of integers.
4. Write a C++ program to find the second lowest and highest numbers in a
given array.
5. Write a C++ program to change every letter in a given string with the letter
following it in the alphabet.
6. Write a C++ program to capitalize the first letter of each word of a given
string. Words must be separated by only one space.
7. Write a C++ program to update every array element by multiplication of next
and previous values of a given array of integers.
8. Write a C++ program to insert a dash character (-) between two odd numbers
in a given string of numbers.
9. Write a simple C++ program to get string input array of fruit names and
display it using for-loop.
10. Write a program using functions to implement Fibonacci series.
11. Write a program using functions to swap two number’s using call by value.
12. Write a program using functions to swap two number’s using call by
reference.
13. Write a program using recursive function to find factorial of given number.

14.Create your own version of the library function strcmp(s1, s2), which compares
two strings and returns –1 if s1 comes first alphabetically, 0 if s1 and s2 are the same,
and 1 if s2 comes first alphabetically. Name your function compstr(). It should take
two char* strings as arguments, compare them character by character, and return an
int. Write a main () program to test the function with different combinations of
strings. Use pointer notation throughout.

15. Write a complete program that prompts the user for the radius of a sphere, and
calculates and prints the volume of that sphere. Use an inline function
sphereVolume that returns the result of the following expression: (4.0 / 3.0 *
3.14159 * pow(radius, 3)).
Structures, Union, and File concepts in C prepared by Dr.S.Suchithra . DSBS

1. Write a C program to store information of n students using structure


2. Write a C program to calculate the difference between two time periods
3. Write a C program to add two distances in feet and inches using structure
4. Write a C program to extract individual bytes from an unsigned int using
union
5. Write a C program to find the size of the union
6. Write a C program to create a file and write contents, save and close the file.
7. Write a C program to read numbers from a file and write even, odd and prime
numbers to separate file.
8. Write a C program to append content to a file.
9. Write a C program to copy contents from one file to another file.
10. Write a C program to copy contents from one file to another file.
11. Write a C program to count characters, words and lines in a text file.
12. Write a C program to remove specific line from a text file.
13. Write a C program to find occurrence of a word in a text file.
14. Write a C program to convert uppercase to lowercase character and vice versa
in a text file.
15. Write a C program to check if a file or directory exists.
16. Write a C program to list all files and sub-directories recursively.

You might also like