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

Assignment_PRF192

The document outlines a series of programming assignments that cover various mathematical and algorithmic problems. Tasks include solving linear and quadratic equations, checking number properties, manipulating arrays and strings, and performing operations on matrices. Each assignment is designed to enhance programming skills through practical applications in mathematics and data structures.

Uploaded by

lemonblub
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment_PRF192

The document outlines a series of programming assignments that cover various mathematical and algorithmic problems. Tasks include solving linear and quadratic equations, checking number properties, manipulating arrays and strings, and performing operations on matrices. Each assignment is designed to enhance programming skills through practical applications in mathematics and data structures.

Uploaded by

lemonblub
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT

PRF192

1. Write a program to find x whereas: ax + b = 0


2. Write a program to solve a quadratic equation: ax2 + bx + c = 0.
3. Write a program that inputs the number n and outputs to the screen how to write that
number n (if 1<=n<=9), if n>9 then output the message: "don't know".
4. Write a program to convert uppercase/lowercase of a letter character.
5. Write a program to input 4 integers. Find the largest and smallest number.
6. Write a program that inputs an integer and checks whether the entered number is even
or odd.
7. Write a program that inputs integers until it reaches 0 and ends. Count how many even
numbers have been entered.
8. Write a program to find the greatest common division and the least common multiple
(LCM) of two numbers a and b entered from the keyboard.
9. Write a program to input from the keyboard: hours, minutes, seconds. Plus a number of
seconds also entered from the keyboard. Please print out the result after completing the
addition.
10. Enter the month and year. Tell how many days there are in that month.
11. Enter d,m,y. Check if the date is valid or not. Output to screen the next day.
12. Enter a positive integer n (n > 0). Calculate:
a) S1 = 1 + 2 + … + n
b) S2 = 1 2 + 2 2 + … + n 2
c) S3 = 1 + 1/2 + … + 1/n
d) S4 = 1*2*…*n
13. Output to the screen the multiplication table from 2 to 9 as follows:
14. Write a program to find the solution to the following problem:
One Hundred of buffaloes, one hundreds of grasses
The standing buffaloes eat five grasses
The lying buffaloes eat three grasses
Three old buffaloes eat one grasses.
How many standing buffaloes, lying buffaloes, and old buffaloes are there?
15. Write functions that print to the screen solid and hollow triangles with height h. Then
write a program to create a menu that allows you to select a triangle shape to print to
the screen.
16. Enter a positive integer n (n > 0). Indicate whether n is
a) Symmetric numbers (eg: 121, 12321...) or not?
b) Perfect square numbers (eg: 4, 9, 16, ...) or not?
c) Prime numbers (eg: 2, 3, 5, 7, ...) or not?
d) Perfect number (also called perfect number): a number whose sum of divisors is
equal to itself.
For example: number 6 and number 28 are complete numbers because 6 =
1+2+3 number 28 = 1+2+4+7+14):
e) Are the digits increasing?
f) Are the digits decreasing?

17. Enter a positive integer n (n > 0). Find:


a) Largest numeric character (eg: n = 32471 has the largest numeric character of 7)
b) The smallest digit (eg: n = 32471 has the smallest digit is 1)
c) Sum of numeric characters (eg: n = 32471 has a total of 17 characters)
d) Find s which is the opposite of n (eg: n = 1234 then s = 4321)
g) Count the number of numeric characters in n
h) Calculate the product of n digits
i) Count the number of odd-numbered characters in n
e) Calculate the sum of even-numbered characters in n
18. Write a program to calculate the area of a triangle according to the following formula:
Circumference CV = a + b + c

Area S = q(q  a )(q  b)(q  c) with q = (a+b+c) /2 (q: is half the circumference).

In which: a,b,c, are the 3 sides of the triangle (check that a,b,c must meet the conditions
to form 3 sides of the triangle).
19. Enter 3 numbers a,b,c. Check to see if a,b,c form 3 sides of a triangle? If yes, please tell
us what kind of triangle it is (regular, right, isosceles, equilateral, isosceles). Calculate
the perimeter and area of the triangle.
20. Output to the screen numbers that are divisors of n (eg: n = 50 includes divisors:
1,2,5,10,25)
21. Output to the screen the sum of numbers that are divisors of n.
For example: With n = 50, the total output is s = 1+2+5+10 +25 = 18
22. Count the number of “divisors” of the positive integer n
23. List all the “odd divisors” of the positive integer n
24. Decompose n into a product of prime factors.
For example: With n = 100, output 100 = 2*2*5*5

ARRAY
Write a program using functions to solve the following problems:
25. Find the value in the array of real numbers "farthest from value x".
EX: 24 45 23 13 43 -12
Value x = 15
Distance from x = 15 to other elements in the array is:
9 30 8 2 28 27
Value in the array farthest from value x is 45
26. Given a one-dimensional array of real numbers, find the segment [a,b] such that this
segment contains all the values in the array (TimDoan).
27. Find the first value in a one-dimensional array of integers whose first digit is an odd
digit. If such a value does not exist in the array, the function will return the value 0.
28. (*) Given a one-dimensional array of integers. Write a function to find the digit that
appears the least in the array (timchuso).
29. Count the number of values ending in 5 in the array of integers (demtancung).
30. List the values that appear in the sequence more than once (lietke). Note: each value is
listed once.
31. Let's check whether the array of integers exists or not. If yes return 1, otherwise return
0.
32. Let's add an element with value x to the array at position k (themvitri).
33. Delete all negative numbers in the array of real numbers (xoaam).
34. Lists increasing sub-sequences in the array (lietkecontang).
35. Given a one-dimensional array of integers a. Let's create array b from array a, so that
array b only contains odd values.
36. Write a function to count the number of prime numbers in a matrix of integers.
37. Calculate the average of positive numbers in a matrix of real numbers.
38. Check whether a matrix row is increasing or not.
39. List rows containing prime numbers in the matrix of integers.
40. Calculate the sum of the elements on the sub-diagonal of a square matrix.
41. Count the number of positive values on the main diagonal in a square matrix of real
numbers.
42. Check whether the matrix is symmetric about the main diagonal or not.

STRING
43. Write a program to calculate the length of a given string without using the built-in
strlen() function.
44. Write a program to reverse a given string.
45. Write a program to concatenate two strings without using the built-in strcat() function.
46. String Comparison: Write a program to compare two strings without using the built-in
strcmp() function.
47. String Copy: Write a program to copy one string to another without using the built-in
strcpy() function.
48. String Palindrome Check: Write a program to check if a given string is a palindrome
or not.
49. String Tokenization: Write a program to tokenize a sentence into words and print each
word separately.
50. Character Frequency Count: Write a program to count the frequency of each character
in a given string.
51. Character Conversion: Write a program to convert all lowercase characters in a string
to uppercase characters.
52. String Search: Write a program to search for a substring within a given string and print
the position of its occurrence.·

You might also like