Download 1. Write program to read two numbers and print the largest one? 2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Location arithmetic wikipedia , lookup

Elementary mathematics wikipedia , lookup

Addition wikipedia , lookup

Elementary arithmetic wikipedia , lookup

Transcript
C++ Programming Questions
Dr. nidhal K. El Abbadi
1.
Write program to read two numbers and print the largest one?
2.
Write program to find (y), where
Y = 3 x2 – 2x + 4
3.
Write program to test number whether it is odd or even?
4.
Write program to find area and perimeter of circle?
5.
Write program to read three numbers and find product, and average of
numbers?
6.
Write program to read three numbers and print the smallest one?
7.
Write program to number whether it is positive or negative?
8.
Write program to find value of (x) from
9.
Write program to find (z) from
2
Z = 5A + 3B / A
when A>= B
2
Z = B – 3A
when B>A
10. Write program to calculate the total salary (TS) using the formula (use
swich-case):
BS + 75 / 100 * BS + 12 if code = “Manger” M for brief
Bs + 35 / 100 * BS + 75 if code = “Engineer” E for brief
TS = {
BS +25 / 100 * BS + 50 if code = “Programmer” P for brief
BS + 20 / 100 *BS +25 if code = “Secretary” S for brief
BS + 30
if code = “Clerk” C for brief
Where BS is the base salary
11. Write program to find the value of X from (use also swich-case):
X=A+B
if j = 1
X=A–b
if j = 2
X=A*B
if j = 3
X=A/B
if j = 4
12. Write program to find the value of (Z) from:
Z = 2 (f (x) + 6 )
where f(x) = x3 +2 x2 + 3
13. Write program to find the value of (Z) from:
Z = ( f(x) – 2 g (x) ) where f (x) = √x
g(x) = x2 -4
1
C++ Programming Questions
Dr. nidhal K. El Abbadi
14. Write program to find value of D, where
D = 3x3 – 2x + 5 if x> 5
D=
if 5 ≥ x ≥ 2
D=
if x> 2
15. Write program to convert time for large number of sec to (hour, minute,
sec)?
16. Write program to test number whether accept dividing by 2 and 3 at the
same time?
17. Write program to test number whether accept dividing by 3 or 5?
18. Write program to read number and find its square and its square root?
19. Assume that the following program have been made:
#include<iostream>
Main() {
Char gap = ‘ ‘ ;
Int
m;n;
float a, b;
char c1, c2
int (a + m) = 12 ;
cin >> a >> b >> m >> n ;;
cout << a+b << c1 ;
gap = a + c2 ;
m=a/b;
cin > c2 ;
cout << n = a * b ;
if ( a = b) cout << “ equal” ;
else
cout << a not equal b ;
}
Correct the above program?
20. Write program to read three numbers and convert each positive number to
negative number?
21. Write program to find value of Y where:
Y = x2 – 1
when x >0
2
C++ Programming Questions
Dr. nidhal K. El Abbadi
Y=1–x
when -3 > x <= 0
2
Y=1/x
when x = -3
22. Write program to exchange two numbers (swap)?
23. Which of the following represent valid variable declaration?
int n = - 10 ;
int x = 2.9 ;
int 2k ;
float y = y * 2 ;
char c = 123 ;
char h = “c” + 23 ;
int !b ;
float c ;
24. Which of the following represent valid identifier?
Seven_11
_unique
Gross-income
Gross$income
2by2
Averag_ weight_of_a_large_pizaa
Object.oriented
Default
@yahoo
25. Add extra brackets to the following expressions to explicitly show the order
in which the operators are evaluated:
(n<= p+q && n >=p – q || n==0)
(++n * q-- / ++p – q )
26. Write program to read number and print the first digit in it?
27. Write program to test number accept dividing by 3 with reminder equal 2.
28. Write program to read three numbers and print them in descending order?
29. Write program to convert temperature in Fahrenheit degree to centigrade
degree, where
C = 5 / 9 * ( f + 32)?
3
C++ Programming Questions
30.
31.
Dr. nidhal K. El Abbadi
Write program to find area of triangle?
Write program to find R, where
R=
a = x/ (y2 + z2 )
b = (x+y) /z
32. Write program to print multiplication table for numbers (1 – 10)?
33. Write program to print numbers from 1-15, each in one line?
34. Write program to print odd numbers in range of numbers between 35 and
250?
35. Write program to find sum of numbers accept dividing by 7 in 100
numbers?
36. Write program to read number and find sum of its digit?
37. Write program to find factorial of any number?
38. Write program to convert decimal number to binary number?
39. Write program to read binary number and find the corresponding decimal
number?
40. Write program to find average of 10 numbers?
41. Write program to find (y), where
Y=
42. Write program to find the largest number among 50 numbers?
43. Write program to find the largest and smallest number in a set of 123
numbers?
44. Write program to test number whether its prime or not?
45. Write program to read 120 numbers and count the positive odd numbers,
and negative even numbers?
46. Write program to find average of set of numbers ended by (-1)?
47. Write program to find number of even numbers in set of numbers ended by
number with first digit equal 7?write program to find average of set of
numbers where the last number in the set equal the first number?
48. Write program to print the following shape:
4
C++ Programming Questions
Dr. nidhal K. El Abbadi
1
1
1
1
1
2
2 3
2 3
4
2 3
4
5
49. Write program to read number and do the following:

Print it in reverse order?

Find the smallest digit in it?

Find the sum of its digit?
50. Write program to simulate calculator with four operation?
51. Write program to print the following shape:
0 3 6 9 12 15
3 6 9 12 15
6 9 12 15
9 12 15
12 15
15
52. Compute the value of Z, where
Z=
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)
53. Write program to find value of (Y) for each of the following:
Y = 1 +2 + 3 + …+ N
Y = 1 + 22 + 33 +...+ Nn
Y = X + X/2 + X/3 + … + X/n
Y = x + x2/2 + x3/3 +….+ xn/n
Y = x + x2/2! + x3/3! + ….+ xn/n!
Y = 1 + 33 + 55 + …. +nn
Y = 1/3 – 1/5 + 1/7 - … +1/33
Y = 3/70 + 6/63 + 9/56 + ….+ 30/7
Y = (x3 -1)/2! + (x6 – 4)/ 5! + (x9 -7)/8! +…. + (x18 -16)/17!
Y = 2/4 + 4/6 + 6/8 + 8/10 + ….+ 18/20
54. Write program to find K, where
5
C++ Programming Questions
K=
Dr. nidhal K. El Abbadi
+
55. Write program to find Y, where
Y = (15+17+19+…+121) ÷ ( 110+ 104+ 98+…+8)
56. Write program to read integer and find the following:
a) Sum of even digits.
b) Largest digit in it.
c) Sum of first and last digit in it.
d) Sum of digits greater than 5.
e) Change each zero digit to 1.
f) Swap first digit with last digit.
57. Compute the value of Z:
Z=
58. Compute the following series:
Z = 2!/3! + 3!/4!+ 4!/5!+…+ 60!/61!
59. Write program to find Y, where
Y = (x-1/x) + ½ ( x-1/x)2 + 1/3 (x-1/x)3 +1/4(x-1/x)4 + … + 1/12(x-1/x)12
60. Let f(1) =1 and f(2) = 1
Then fill the next 15 position in f, so that every entry is the sum of the previous
two entries. (i.e. f(3) = f(1) + f(2), f(4) = f(2) + f(3) )
61. A group of 150 colored ball (red, green, yellow, white, black, and blue).
Write program which read the color of each ball as a character (‘ r ‘ for red
and ‘ g ‘ for green and so on), and find the number of balls for each color.
62. Write program which read list of integer numbers ended by 56, and
compute;
a) Number of these integers.
b) The product of them.
c) The average of them.
d) Number of even numbers in the list.
e) Number of integers accepts dividing by 5.
6
C++ Programming Questions
Dr. nidhal K. El Abbadi
f) Maximum number in the list.
g) Order of minimum number in the list.
63. Compute Z from the following
(Hint: count up to 20 term)
Z
64. Compute Y from the following:
Y=
7