Problem Solving Skills - Programs for Practice - Use JAVA /C /C++
1. Write a program to accept a number N and print whether the number is EVEN or ODD.
2. Write a program to accept two numbers and print whether their sum is EVEN or ODD
3. Write a program to print all numbers from 1 to 100 Le. 1 2 3 4 5 6 7 . . . 98 99 100
4. Write a program to print alternate numbers starting from 1 to 99 Le. 1 3 5 7 9 11 13 . . . 95 97 99
5. Write a program to print alternate numbers starting from O to 100 Le. 0 2 4 6 8 10 12 . . . 96 98 100
6. Write a program to print all numbers backwards from 100 to 0 Le. 100 99 98 97 96. . . 4 3 2 1 O
7. Write a program to print numbers backwards from 100 to 1 by skipping 2 numbers i.e. 100 97 94 91 88..10 7 4 1
8. Print the below shape on a console window [n rows right-angled left justified numbers]
1
12
123
1234
9. Print the below shape on a console window [n rows right-angled right justified stars]
*
**
***
****
10.Print the below shape on a console window [n rows triangle]
1
121
12321
1234321
11.Print the below shape on a console window [n rows triangle]
1
12A
123BA
1234CBA
12.Print the below shape on a console window [n rows rohombus]
1
121
12321
1234321
12321
121
1
11. Write a program to swap values of two numbers using third variable.
12. Given a set of 3 student's examination marks (in the range from 0 to 100), make a count of the number of students that have passed the exam. A pass is awarded if the students mark is greater than or equal to 35.
13. Design an algorithm that reads a list of 5 numbers (both +ve and -ve) and makes a count of the number of negative and non-negative numbers in the list. Note - 0 must be considered as a +ve number in this algorithm.
14. Write a program to get a number from user and check if it is even or odd or a zero.
15. Write a program to get a 3 numbers from user and display its sum.
16. Write a program to count the number of digits in a given number.
17. Write a program to find the sum of all the digits in a given number.
18. Write a program which accepts a decimal number and then displays its corresponding binary representation.
19. Write a program which accepts a binary representation of a number and then displays its corresponding decimal equivalent.
20. Write a program which accepts a number from the user and displays its smallest exact divisor other than one.
21. Write a program to read 10 numbers from the user to find their average and also find out how many integers are less than the average.
22. Write a program to accept 10 integer elements for an array and print the sum of all the elements.
23. Write a program to accept 20 integer elements for an array and print the maximum 3 and minimum 3 elements from the array.
Note: Sorting of array elements not allowed.
24. Write a program to accept 10 integer elements for an array and then rearrange the elements in the array in reverse order. The reversed array must be displayed as output.
25. Write a program which accepts a set of N (consider N to be 30) student’s examination marks (in the range of 0 to 100). Then make a count of the number of students that obtain each possible mark (i.e.;count of how many students scored 0, count of how many students scored 1,.. till count of how many students scored 100)
26. Modify above program and display output of count in 0-10%, 10%-20%.... 90%-100% form.
27. Write a program to calculate length of string without using in built functions.
28. Write a program to accept a string from the user. Reverse the string and display it without using in built functions..
29. Write a program to accept a string from the user. Replace all vowels (‘a’, ‘e’, ‘I', ’o', ’u') with 'z'. If there are no vowels in the string just print the original word with the message ”No vowels present”.
30. Write a program to accept 2 strings (stringl and string2) from the user. Concatenate both the strings into a third string ”string3” and print the result.
Example
stringl = ”Hello"
string2 = ”World"
string3 must be ”HeIIoWorId"
31. Write a program to accept a string from the user. Count and print the number of times each
character occurs in the given string.
Example input string = ”malayalam"
Output must be
m - 2
a - 4
I - 2
y - 1
32. Write a program to accept 10 integer elements for an array and rearrange the elements in descending order. The new array must be printed to the user.
33. Write a program to remove all duplicate elements from an ordered array (may be ascending or descending order) and contract the array accordingly.
For Example
Input Array is
2 4 2 5 3 4 6 5 1 7
After ordering
1 2 2 3 4 4 5 5 6 7
Output array must be
1 2 3 4 5 6 7
34. Write a program to accept 25 integer elements for an array. Then find the number with the maximum value in the set and the position
where it occurs first
where it occurs last
1. Write a program to accept a number N and print whether the number is EVEN or ODD.
2. Write a program to accept two numbers and print whether their sum is EVEN or ODD
3. Write a program to print all numbers from 1 to 100 Le. 1 2 3 4 5 6 7 . . . 98 99 100
4. Write a program to print alternate numbers starting from 1 to 99 Le. 1 3 5 7 9 11 13 . . . 95 97 99
5. Write a program to print alternate numbers starting from O to 100 Le. 0 2 4 6 8 10 12 . . . 96 98 100
6. Write a program to print all numbers backwards from 100 to 0 Le. 100 99 98 97 96. . . 4 3 2 1 O
7. Write a program to print numbers backwards from 100 to 1 by skipping 2 numbers i.e. 100 97 94 91 88..10 7 4 1
8. Print the below shape on a console window [n rows right-angled left justified numbers]
1
12
123
1234
9. Print the below shape on a console window [n rows right-angled right justified stars]
*
**
***
****
10.Print the below shape on a console window [n rows triangle]
1
121
12321
1234321
11.Print the below shape on a console window [n rows triangle]
1
12A
123BA
1234CBA
12.Print the below shape on a console window [n rows rohombus]
1
121
12321
1234321
12321
121
1
11. Write a program to swap values of two numbers using third variable.
12. Given a set of 3 student's examination marks (in the range from 0 to 100), make a count of the number of students that have passed the exam. A pass is awarded if the students mark is greater than or equal to 35.
13. Design an algorithm that reads a list of 5 numbers (both +ve and -ve) and makes a count of the number of negative and non-negative numbers in the list. Note - 0 must be considered as a +ve number in this algorithm.
14. Write a program to get a number from user and check if it is even or odd or a zero.
15. Write a program to get a 3 numbers from user and display its sum.
16. Write a program to count the number of digits in a given number.
17. Write a program to find the sum of all the digits in a given number.
18. Write a program which accepts a decimal number and then displays its corresponding binary representation.
19. Write a program which accepts a binary representation of a number and then displays its corresponding decimal equivalent.
20. Write a program which accepts a number from the user and displays its smallest exact divisor other than one.
21. Write a program to read 10 numbers from the user to find their average and also find out how many integers are less than the average.
22. Write a program to accept 10 integer elements for an array and print the sum of all the elements.
23. Write a program to accept 20 integer elements for an array and print the maximum 3 and minimum 3 elements from the array.
Note: Sorting of array elements not allowed.
24. Write a program to accept 10 integer elements for an array and then rearrange the elements in the array in reverse order. The reversed array must be displayed as output.
25. Write a program which accepts a set of N (consider N to be 30) student’s examination marks (in the range of 0 to 100). Then make a count of the number of students that obtain each possible mark (i.e.;count of how many students scored 0, count of how many students scored 1,.. till count of how many students scored 100)
26. Modify above program and display output of count in 0-10%, 10%-20%.... 90%-100% form.
27. Write a program to calculate length of string without using in built functions.
28. Write a program to accept a string from the user. Reverse the string and display it without using in built functions..
29. Write a program to accept a string from the user. Replace all vowels (‘a’, ‘e’, ‘I', ’o', ’u') with 'z'. If there are no vowels in the string just print the original word with the message ”No vowels present”.
30. Write a program to accept 2 strings (stringl and string2) from the user. Concatenate both the strings into a third string ”string3” and print the result.
Example
stringl = ”Hello"
string2 = ”World"
string3 must be ”HeIIoWorId"
31. Write a program to accept a string from the user. Count and print the number of times each
character occurs in the given string.
Example input string = ”malayalam"
Output must be
m - 2
a - 4
I - 2
y - 1
32. Write a program to accept 10 integer elements for an array and rearrange the elements in descending order. The new array must be printed to the user.
33. Write a program to remove all duplicate elements from an ordered array (may be ascending or descending order) and contract the array accordingly.
For Example
Input Array is
2 4 2 5 3 4 6 5 1 7
After ordering
1 2 2 3 4 4 5 5 6 7
Output array must be
1 2 3 4 5 6 7
34. Write a program to accept 25 integer elements for an array. Then find the number with the maximum value in the set and the position
where it occurs first
where it occurs last
No comments:
Post a Comment