Program 1: Given two positive numbers M and N, such that M is between 100 and 10000 and N is less than 100. Find the smallest integer that is greater than M and whose digits add up to N. For example, if M = 100 and N = 11, then the smallest integer greater than 100 whose digits add up to 11 is 119.
Write a program to accept the numbers M and N from the user and print the smallest required number whose sum of all its digits is equal to N. Also, print the total number of digits present in the required number. The program should check for the validity of the inputs and display an appropriate message for an invalid input.
Test your program with the sample data and some random data:
Example 1
INPUT :
M = 100
N = 11
OUTPUT :
The required number = 119
Total number of digits = 3
Example 2
INPUT :
M = 1500
N = 25
OUTPUT :
The required number = 1699
Total number of digits = 4
Example 3
INPUT :
M = 99
N = 11
OUTPUT :
INVALID INPUT
Example 4
INPUT :
M = 112
N = 130
OUTPUT :
INVALID INPUT
Question 2.
Write a program to declare a square matrix A[][] of order M x M where ‘M’ is the
number of rows and the number of columns, such that M must be greater than 2 and less
than 10. Accept the value of M as user input. Display an appropriate message for an
invalid input. Allow the user to input integers into the matrix. Perform the following
tasks:
a) Display the original matrix.
b) Rotate the matrix 90ยบ clockwise as shown below:
Original matrix Rotated matrix
1 2 3 7 4 1
4 5 6 8 5 2
7 8 9 9 6 3
c) Find the sum of the elements of the four corners of the matrix. Test your program
for the following data and some random data:
Example 1:
INPUT : M=3
3 4 9
2 5 8
1 6 7
OUTPUT:
ORIGINAL MATRIX
3 4 9
2 5 8
1 6 7
MATRIX AFTER ROTATION
1 2 3
6 5 4
7 8 9
Sum of the corner eements= 20
Example 2:
INPUT : M=4
1 2 4 9
2 5 8 3
1 6 7 4
3 7 6 5
OUTPUT:
ORIGINAL MATRIX
1 2 4 9
2 5 8 3
1 6 7 4
3 7 6 5
MATRIX AFTER ROTATION
3 1 2 1
7 6 5 2
6 7 8 4
5 4 3 9
Sum of the corner eements= 18
EXAMPLE 3.
INPUT : M = 14
OUTPUT:
SIZE OUT OF RANGE
For Solution: CLICK HERE
Write a program to accept a sentence which may be terminated by either ‘.’ Or ‘?’ only.
The words are to be separated by a single blank space. Print an error message if the input
does not terminate with ‘.’ Or ‘?’. You can assume that no word in the sentence exceeds
15 characters, so that you get a proper formatted output. Perform the following tasks:
i) Convert the first letter of each word to uppercase.
ii) Find the number of vowels and consonants in each word and display them
with proper heading along with the words.
Test your program with the following inputs:
4
Example 1
INPUT : Intelligence plus character is education.
OUTPUT:
Intelligence plus character is education.
Word Vowels Consonants
Intelligence 5 7
Plus 1 3
Character 3 6
Is 1 1
Education 5 4
Example 2
INPUT : God is great.
OUTPUT:
God is great
Word Vowels Consonants
God 1 2
Is 1 1
Great 2 3
For Solution: CLICK HERE
For the complete solution along with variable description and algorithm: CLICK HERE
2010 To 2018 Complete 9 Years Papers With Solutions: CLICK HERE
see the output of question 3!!
ReplyDeleteEnter the sentence:intellegence plus charecter is education.
Modified sentence:Intellegence Plus Charecter Is Education
Word Vowels Consonents
Intellegence 5 7
Plus 1 3
Charecter 3 6
Is 1 1
Education 5 4
Not Clear
Delete