Escolar Documentos
Profissional Documentos
Cultura Documentos
Selection
Write a program that will input a character then classify it as small or capital. Char x; Cout << input a letter ; Cin >> x; If (x >= a && x <= z ) Cout << small letter ; Else Cout << capital letter ;
1.
2. Write a program that will input a character and classify it as character or digit. Char x ; Cout << input a character ; Cin >> x; If ( x >= A && x <= z) Cout << letter; If (x >= 0 && x <= 9) Cout << digit; 3. Write a program that will input a character and check if it's special character or not. Char x ; Cout << input a character ; Cin >> x; If ( (x >= 0 && x <= 9) || ( x >= A && x <= z) ) Cout << not a special character ; Else Cout << a special character ; 4. Write a program that will input 2 integers x and y and check if x is multiple of y. Int x ,y ; Cout << input two integers x , y ; Cin >> x , y ; If ( (x%y) == 0 ) Cout << x is multiple of y ;
5. Write a program that will input 2 integers x and y and check if y is multiple of x. Int x ,y ; Cout << input two integers x , y ; Cin >> x , y ; If ( (y%x) == 0 ) Cout << y is multiple of x ; 6. Write a program that will input 2 integers x and y and check if they both are multiples of 5. Int x ,y ; Cout << input two integers x , y ; Cin >> x , y ; If ( (x%5) == 0 && (y%5) == 0 ) Cout << x & y are multiples of 5 ; 7. Write a program that will input 2 integers x and y and check if any of them is multiple of 7. Int x ,y ; Cout << input two integers x , y ; Cin >> x , y ; If ( (x%7) == 0 ) Cout << x is multiple of 7 ; If ((y%7) == 0 ) Cout << y is multiple of 7 ; 8. Repeat question 6 using Conditional Operator ? : 9. Repeat question 7 using Conditional Operator ? : 10. Write a program to check whether an integer number (0-999) has 1 or 2 or 3 digits. Int x ; Cout << input an integer between ( 0 999 ) ; Cin >> x ; If (x>= 0 && x <= 9 ) Cout << it is consisted of one digit ; If (x>= 10 && x <= 99 ) Cout << it is consisted of two digits ; If (x>= 100 && x <= 999 ) Cout << it is consisted of three digits ;
Write a program to check if an integer number divides by 11 or not. Int x ; Cout << input an integer ; Cin >> x; If ((x%11) == 0) Cout >> it devides by 11 ;
11.
12. Write a program that will input 2 integers and check if their sum is even or odd. Int x ,y ; If ( ((x+y) % 2) == 0 ) Cout << the sum of the two integers is even ; Else Cout << the sum of the two integers is odd ; 13. Write a program that will input 2 integers with mathematical operation in between, then print the result of the operation (using nested if). Int x , y ; Char z ; Cout << input two integers with mathematical operation in between ; Cin >> x , z, y ; If ( z == + ) Cout << x + y ; If ( z == - ) Cout << x y ; If (z ==*) Cout << x * y ; If ( z == / ) Cout << x / y ;
14. Repeat question 13 using switch . case. Int x , y ; Char z ; Cout << input two integers with mathematical operation in between ; Cin >> x , z, y ; Switch (z) { case + : Cout << x + y ; break ; case - : Cout << x - y ; break ; case * : Cout << x * y ; break ; case / : Cout << x / y ; break ; } 15. Write a program that will input a real number then print its rounded value (according to its decimal part).
Cout << y ;