0% found this document useful (0 votes)
48 views16 pages

TTT Program Question (Arunachalam)

The document contains a series of programming questions and solutions related to basic arithmetic, array manipulation, pattern printing, and character checks. Each question includes input and output formats, sample inputs and outputs, as well as C code solutions. The topics covered include digit sum calculation, grocery price calculation, matrix addition, half pyramid patterns, array reversal, odd/even number identification, vowel checking, alphabet validation, factorial calculation, and day of the week identification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views16 pages

TTT Program Question (Arunachalam)

The document contains a series of programming questions and solutions related to basic arithmetic, array manipulation, pattern printing, and character checks. Each question includes input and output formats, sample inputs and outputs, as well as C code solutions. The topics covered include digit sum calculation, grocery price calculation, matrix addition, half pyramid patterns, array reversal, odd/even number identification, vowel checking, alphabet validation, factorial calculation, and day of the week identification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question 1:

Ram is small boy. His father gives him a number and ask him to calculate the sum of the
digits in that number till the answer comes in singe digit. As ram is a small boy he doesn't
knows how to calculate. So help him to Find the sum of the digits untill it reaches to
single digit.

Input Format:
Input consists of 1 integer.

Output Format:
Output consists of the sum of the digits in the given number

Constraints:
0<number<10^15

Sample Input:
2567

Sample Output:
2

Solution:

#include<stdio.h>
int main()
{
int n ;
scanf("%d",&n);
int sum = 0;
while(n > 0 || sum > 9)
{
if(n == 0)
{
n = sum;
sum = 0;
}
sum += n % 10;
n /= 10;
}
printf("%d",sum);
return 0;
}

Test Cases:
case = t1
input=25678
output=1
case=t2
input=389178
output=9

case=t3
input=589123489
output=4

case=t4
input=314
output=8

case=t5
input=459
output=9

Question 2:

Cibi runs grocery shop. There she sells Apple, Diarymilk Chocolate, Rice & Wheat. The prices
of the products where Apple=Rs.20/kg, Diarymik=Rs.30/piece, Rice=Rs.102/kg,
Wheat=74/kg. The customers wants the prices of the products separately and the total
amount. So help Cibi to Calculate the prices separately.

Input Format:
Input consists of 4 numbers it may be in integer or in float recordingly.
1st input is no.of kilos of apple.
2nd input is no.of pieces of diarymilk.
3rd input is no.of kilos of rice.
4th input isno.of kilos wheat.

Output Format:
Output consists of 5 floating numbers(correct the decimal places to 2)
1st amount of apples they bought.
2nd amount of diarymilk they bought.
3rd amount of rice they bought.
4th amount of wheat they bought.
5th total amount they wants to pay.

Constraints:
0<inputs<10^15

Sample Input:
2
4
6.5
3.4

Sample Output:
40.00
120.00
663.00
251.60
1074.60

Solution:

#include<stdio.h>
int main()
{
float a,d,r,w,ta,td,tr,tw,t;
scanf("%f%f%f%f",&a,&d,&r,&w);
ta=a*20;
td=d*30;
tr=r*102;
tw=w*74;
t=ta+td+tr+tw;
printf("%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n",ta,td,tr,tw,t);
return 0;
}

Test Cases:
case = t1
input=2
4
6.5
3.4
output=40.00
120.00
663.00
251.60
1074.60

case = t2
input=4.6
3
2.4
4.7
output=92.00
90.00
244.80
347.80
774.60

case = t3
input=7.2
5
74.2
22
output=144.00
150.00
7568.40
1628.00
9490.40

case = t4
input=42.7
8
104.9
30.4
output=854.00
240.00
10699.80
2249.60
14043.40

case = t5
input=108.8
73
228
20.5
output=2176.00
2190.00
23256.00
1517.00
29139.00

Question 3:
Janu is good at handleing collection of numbers. For example u give her 2 sets of number list
she gives u the sum of the numbers in a set format ie, addition of array. Her friends wants to
perform the operation regarding the numbers they give. Janu accepted it and does the
addition of the array.

Input Format:
1. Number of rows.
2. Number of columns.
3. Values of the array1.
4. Values of the array2.
5. all should be integers.

Output Format:
Output consists of integer values of Resultant array list.

Constraints:
0<rows,columns<10
0<elements<500

Sample Input:
1
2
14
35
Sample Output:
49

Solution:

#include <stdio.h>
int main() {
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
scanf("%d", &r);
scanf("%d", &c);

for (i = 0; i < r; ++i)


for (j = 0; j < c; ++j) {

scanf("%d", &a[i][j]);
}

for (i = 0; i < r; ++i)


for (j = 0; j < c; ++j) {

scanf("%d", &b[i][j]);
}

// adding two matrices


for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
sum[i][j] = a[i][j] + b[i][j];
}

// printing the result

for (i = 0; i < r; ++i)


for (j = 0; j < c; ++j) {
printf("%d ", sum[i][j]);
}
printf("\n");
}

return 0;
}

Test Cases:

case = t1
input=1
2
1
4
3
5
output=4 9

case = t2
input=2
2
2
5
4
7
5
8
9
3
output=7 13
13 10

case = t3
input=3
3
5
45
20
29
30
26
46
56
27
11
39
56
62
74
96
75
82
92
output=16 84 76
91 104 122
121 138 119

case = t4
input=3
4
101
16
34
46
74
102
18
17
96
34
44
24
102
17
24
44
86
96
76
56
7
17
28
48
output=203 33 58 90
160 198 94 73
103 51 72 72

case = t5
input=2
3
100
406
562
321
28
94
62
74
32
47
97
108
output=162 480 594
368 125 202

Question 4:
Ravi is intrested in playing with patterns. He asked his friends to give him a number, letter
or symbol, he will print that in half pyramid pattern. He started playing with his friends to
print half pyramid pattern.
Input Format:
Input consists of 2 lines
1st line is how many rows
2nd line is what should be print
Output Format:
Half Pyramid Pattern of the given input
Sample Input:
2
3
Sample Output:
3
33

Solution:
#include <stdio.h>
int main() {
int i, j, rows;
char a;
scanf("%d %c", &rows,&a);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("%c ",a);
}
printf("\n");
}
return 0;
}

Test Cases:
case=t1
input=2
3
output=3
33

case=t2
input=4
Q
output=Q
QQ
QQQ
QQQQ

case=t3
input=6
*
output=*
**
***
****
*****
******

case=t4
input=7
a
output=a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa

case=t5
input=4
$
output=$
$$
$$$
$$$$

Question 5:
A land called Array Reversal. It have a special power that if we gives a set of numbers in
order it gives the set of numbers in reverse order. Lets see how it works on reverse the
numbers in a array.
Input Format:
First line of input consists of the number of elements in array.
from second line type the elements of array.
Output Format:
Output shows the Reversed array.
Sample Input:
5
2
5
6
7
8
Sample Output:
87652

Solution :
#include<stdio.h>
int main()
{
int n, arr[100], i;
scanf("%d", &n);

for(i = 0; i < n; i++)


{
scanf("%d", &arr[i]);
}
int rev[n], j = 0;
for(i = n-1; i >= 0; i--)
{
rev[j] = arr[i];
j++;
}

for(i = 0; i < n; i++)


{
printf("%d ", rev[i]);
}
}

Test Cases:
case=t1
input=3
5
6
7
output=7 6 5

case=t2
input=6
22
44
78
90
889
76
output=76 889 90 78 44 22

case=t3
input=9
9
88
77
99
90
56
77
87
23
output=23 87 77 56 90 99 77 88 9

case=t4
input=4
90
99
0
999
output=999 0 99 90

case=t5
input=5
8
7
6
5
4
output=4 5 6 7 8

Question 6:
Hari is a mysterious boy. Who has the power of find odd or even in a set of numbers. lets
check his power.
Input Format:
1st line consists of an integer of size of the array
enter the values of array
Output Format:
Output shows the odd, even numbers respectively
Sample Input:
5
20
5
3
6
7
Sample Output:
Odd numbers in Array:
537
Even numbers in Array:
20 6
Solution:
#include <stdio.h>
void main()
{
int n;

scanf("%d", &n);

int arr[n];

//Take n elements as input from the user

for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}

//Print all the even numbers


printf("Odd numbers in Array:\n");
for(int i=0;i<n;i++)
{
if(arr[i]%2==1)
printf("%d ", arr[i]);
}

//print all the odd numbers


printf("\nEven numbers in Array:\n");
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
printf("%d ", arr[i]);
}
}

Test cases:
case=t1
input=3
12
13
78
output=Odd numbers in Array:
13
Even numbers in Array:
12 78

case=t2
input=4
9
8
7
6
output=Odd numbers in Array:
97
Even numbers in Array:
86

case=t3
input=5
3
5
6
89
90
output=Odd numbers in Array:
3 5 89
Even numbers in Array:
6 90
case=t4
input=8
12
34
55
65
78
90
77
99
output=Odd numbers in Array:
55 65 77 99
Even numbers in Array:
12 34 78 90

case=t5
input=7
12
31
42
55
57
89
70
output=Odd numbers in Array:
31 55 57 89
Even numbers in Array:
12 42 70
Question 7:
As Ram was intrested in alphabets he wants to find whether the given alphabet is vowel or
not. So help him to Find out whether the character is vowel or not.
Input Format:
A Character to find it is vowel or not(only lower case)
Output Format:
Output shows whether the input is vowel or not;
Sample Input1:
a
Sample Output1:
a is vowel
Sample Input2:
b
Sample Output2:
b is not a vowel

Solution:
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);

// evaluates to 1 if variable c is a lowercase vowel


lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 if variable c is a uppercase vowel
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

// evaluates to 1 (true) if c is a vowel


if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel", c);
else
printf("%c is not a vowel", c);
return 0;
}

Question 8:
Harsith is working on alphabets. His friends gives him some values. He wants to find out the
given values are alphabets or not, So help him to Find out whether the given value is
alphabet or not.

Input Format:
input consists of any value(alphabets ,numbers, symbols)

Output Format:
Output shows whether the given value is alphabet or not

Sample Input 1:
d

Sample Output 1:
d is an Alphabet

Sample Input 2:
1

Sample Output 2:
1 is not an Alphabet

Solution:
#include <stdio.h>
int main() {
char c;
scanf("%c", &c);

if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
printf("%c is an Alphabet", c);
else
printf("%c is not an Alphabet", c);

return 0;
}

Test Cases:
case=t1
input=a
output=a is an alphabet

case=t2
input=1
output=1 is not an alphabet

case=t3
input=@
output=@ is not an alphabet

case=t4
input=e
output=e is an alphabet

case=t5
input=!
output=! is not an alphabet

Question 9:
Hari is intrested to working with numbers. His father gives him a number and says that take
the given number as n and find the factorial of the given number. So help him to find out the
Factorial of Given number.
Input Format:
Input consists of an integer
Constraints:
0<n<100
Output Format:
Output is also an integer of factorial of given number
Sample Input:
5
Sample Output:
120

Solution:
#include<stdio.h>
int main()
{
int i,fact=1,number;
scanf("%d",&number);
for(i=1;i<=number;i++){
fact=fact*i;
}
printf("%d",fact);
return 0;
}

Question 10:
Ram is a school boy. He prepared a calender from sunday to saturday by assign numbers
from 1 to 7. If you put 1 it shows sunday. Lets see how it works.
Input Format:
An integer from 1 to 7
Output Format:
Ouput shows Sunday to Saturday regarding the input
Sample Input:
2
Sample Output:
Monday
Solution:
#include<stdio.h>
int main()
{
int day;
scanf("%d",&day);
switch (day) {
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
case 7:
printf("Saturday");
break;
}

return 0;
}

Test Cases:
case=t1
input=1
output=Sunday

case=t2
input=2
output=Monday

case=t3
input=3
output=Wednesday

case=t4
input=6
output=Friday

case=t5
input=7
output=Saturday

You might also like