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

Tcs Digital Question

The documents contain test cases and sample inputs/outputs for several C programming problems involving: - Checking if a year is a leap year - Converting temperatures between Celsius and Fahrenheit - Rearranging arrays in alternating ascending/descending order - Checking if a number is odd or even - Finding the sum of digits in a number - Calculating the area of a triangle given three sides - Checking if a number is prime and calculating its square root - Checking if a number is a palindrome - Finding the sum of prime numbers within a given range - Adding two numbers in binary The test cases provide example inputs and outputs to test the programs for these problems.

Uploaded by

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

Tcs Digital Question

The documents contain test cases and sample inputs/outputs for several C programming problems involving: - Checking if a year is a leap year - Converting temperatures between Celsius and Fahrenheit - Rearranging arrays in alternating ascending/descending order - Checking if a number is odd or even - Finding the sum of digits in a number - Calculating the area of a triangle given three sides - Checking if a number is prime and calculating its square root - Checking if a number is a palindrome - Finding the sum of prime numbers within a given range - Adding two numbers in binary The test cases provide example inputs and outputs to test the programs for these problems.

Uploaded by

Meenakshi Patel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Leap year or Not

Write a c program, to check whether the given year is a leap year or not A leap year is a calendar
year containing one additional day(Feb 29th)added to keep the calendar year synchronized with
the astronomical year.
Sample input
2016
Sample output
Enter year : 2016
leap year
Testcase 1
Input
2016
Output
Enter year : 2016
leap year
Testcase 2
Input
1997
Output
Enter year : 1997
Not leap year
Testcase 3
Input
2008
Output
Enter year : 2008
Leap year
Testcase 4
Input
1973
Output
Enter year : 1973
Not leap year
Testcase 5
Input
1988
Output
Enter year : 1988
Leap year
Testcase 5
Input
2010
Output
Enter year : 2010
Not leap year
Testcase 6
Input
1956
Output
Enter year : 1956
Leap year
Testcase 7
Input
1950
Output
Enter year : 1950
Not leap year
Testcase 8
Input
2000
Output
Enter year : 2000
Leap year

Write a C program to input temperature in Centigrade and


convert to Fahrenheit
Sample input
32
Sample output
Enter temperature in Celsius :
Temperature in Fahrenheit : 89.59998
Testcase1
Input
32
Output
Enter temperature in Celsius :
Temperature in Fahrenheit : 89.59998
Testcase2
Input
10
Output
Enter temperature in Celsius : 10
Temperature in Fahrenheit : 50.000000
Testcase3
Input
78
Output
Enter temperature in Celsius : 78
Temperature in Fahrenheit : 172.399994
Testcase4
Input
90
Output
Enter temperature in Celsius : 90
Temperature in Fahrenheit : 194.000000
Testcase5
Input
12
Output
Enter temperature in Celsius : 12
Temperature in Fahrenheit : 53.599998
Testcase6
Input
88
Output
Enter temperature in Celsius : 88
Temperature in Fahrenheit : 190.399994
Testcase7
Input
104
Output
Enter temperature in Celsius : 104
Temperature in Fahrenheit : 219.199997
Testcase8
Input
104
Output

Half Ascending Half Descending


Get an unsorted array and convert into alternate array(alternate arrayascending order array by
taking
alternate elements).Half elements of array in ascending remaining half in descending.The
first n
elements should be sorted in ascending order and the next part should be sorted in descending
and
print it
Function:
fn_name(input array, length of array, no of digits to sort (here 3))
Sample input
8
12345678
Sample output
Enter array size : 8
Enter array elements :
12345678
12348765

Testcase 1
Input
8
12345678
Output
Enter array size : 8
Enter array elements :
12345678
12348765
Testcase 2
Input
6
801523
Output
Enter array size : 6
Enter array elements : 8 0 1 5 2 3
018532
Testcase 3
Input
5
93628
Output
Enter array size : 5
Enter array elements : 9 3 6 2 8
39862
Testcase 4
Input
10
9092167429
Output
Enter array size : 10
Enter array elements : 9 0 9 2 1 6 7 4 2 9
0129997642
Testcase 5
Input
4
5835
Output
Enter array size : 4
Enter array elements : 5 8 3 5
5853
Testcase 5
Input
7
9876543
Output
Enter array size : 7
Enter array elements : 9 8 7 6 5 4 3
7896543
Testcase 6
Input
3
451
Output
Enter array size : 3
Enter array elements : 4 5 1
451
Testcase 7
Input
5
97552
Output
Enter array size : 5
Enter array elements : 9 7 5 5 2
79552
Testcase 8
Input
6
795376
Output
Enter array size : 6
Enter array elements : 7 9 5 3 7 6
579763

Odd or Even

Write a C program to check if a given number is odd or even


Sample input
7
Sample output
Enter an integer:
7 is odd
Testcase 1
Input
7
Output
Enter an integer:
7 is odd
Testcase 2
Input
5
Output
Enter an integer:
5 is odd
Testcase 3
Input
6
Output
Enter an integer:
6 is even
Testcase 4
Input
9
Output
Enter an integer:
9 is odd
Testcase 5
Input
2
Output
Enter an integer:
2 is even
Testcase 6
Input
13
Output
Enter an integer:
13 is odd
Testcase 7
Input
20
Output
Enter an integer:
20 is even
Testcase 8
Input
3
Output
Enter an integer:
3 is odd

Sum Of Digits
Write a program to print the sum of digits of a number
Problem Description
This program computes the sum of digits in a given integer.
Sample input
12345
Sample output
Enter an integer
12345
Sum of digits of 12345=15
Testcase 1
Input
12345
Output
Enter an integer
12345
Sum of digits of 12345=15
Testcase 2
Input
90921
Output
Enter an integer
90921
Sum of digits of 90921 = 21
Testcase 3
Input
97505
Output
Enter an integer
97505
Sum of digits of 97505 = 26
Testcase 4
Input
987654321
Output
Enter an integer
987654321
Sum of digits of 987654321 = 45
Testcase 5
Input
13578
Output
Enter an integer
13578
Sum of digits of 13578 = 24
Testcase 5
Input
148976
Output
Enter an integer
148976
Sum of digits of 148976 = 35
Testcase 6
Input
80152208
Output
Enter an integer
80152208
Sum of digits of 80152208 = 26
Testcase 7
Input
099765
Output
Enter an integer
099765
Sum of digits of 99765 = 36
Testcase 8
Input
135798642
Output
Enter an integer
135798642
Sum of digits of 135798642 = 45

Area Of Triangle
Write a program to find the area of triangle. given a,b,c
Problem Description
The program takes three sides of a triangle and prints the area formed by all three sides.
Sample input
15 9 7
Sample output
Enter the values of a,b,c
15 9 7
The area of a trangle is:20.69
Testcase1
Input
15 9 7
Output
Enter the values of a,b,c
15 9 7
The area of a trangle is:20.69
Testcase2
Input
469
Output
Enter the values of a,b,c
469
The area of a trangle is:9.56
Testcase3
Input
597
Output
Enter the values of a,b,c
597
The area of a trangle is:17.41
Testcase4
Input
12 8 6
Output
Enter the values of a,b,c
12 8 6
The area of a trangle is:21.33
Testcase5
Input
40 50 27
Output
Enter the values of a,b,c
40 50 27
The area of a trangle is:538.31
Testcase6
Input
28 23 15
Output
Enter the values of a,b,c
28 23 15
The area of a trangle is:172.34
Testcase7
Input
775
Output
Enter the values of a,b,c
775
The area of a trangle is:16.35
Testcase8
Input
12 11 8
Output
Enter the values of a,b,c
12 11 8
The area of a trangle is:42.79

Program: U need to get a input number from user then check whether the no. is prime no. or
not ...if
it is prime no. need print the square root of a no. else print 0.00. eg 7 means the op is 2.65.
Sample input
7
Sample output
2.65
Testcase 1
Input
7
Output
2.65
Testcase 2
Input
8
Output
0.00
Testcase 3
Input
3
Output
1.73
Testcase 4
Input
22
Output
0.00
Testcase 5
Input
33
Output
0.00
Testcase 6
Input
17
Output
4.12
Testcase 7
Input
23
Output
4.80
Testcase 8
Input
66
Output
0.00

Square Root
write a program to find the square root of a number
Problem Description
This program allows the user to enter any number and then finds the square root of that
number using
math function sqrt()
Sample input
3
Sample output
Enter any Number to find Square root:3
Square Root a given number 3.00=1.73
Testcase 1
Input
3
output
Enter any Number to find Square root:3
Square Root a given number 3.00=1.73
Testcase 2
Input
2
output
Enter any Number to find Square root: 2
Square Root a given number2.00=1.41
Testcase 3
Input
15
output
Enter any Number to find Square root: 15
Square Root a given number15.00=3.87
Testcase 4
Input
38
output
Enter any Number to find Square root: 38
Square Root a given number38.00=6.16
Testcase 5
Input
18
output
Enter any Number to find Square root: 18
Square Root a given number18.00=4.24
Testcase 6
Input
27
output
Enter any Number to find Square root: 27
Square Root a given number27.00=5.20
Testcase 7
Input
65
output
Enter any Number to find Square root: 65
Square Root a given number65.00=8.06
Testcase 8
Input
50
output
Enter any Number to find Square root: 50
Square Root a given number50.00=7.07

Palindrome or Not
Program Description
Write a C program which will check a given number N is a palindrome. An integer is a
palindrome if the reverse number equal to the original number. The given number N will be
positive 5digit number . If the given number is a palindrome, then print the word YES to
printf.
If the given number is not a palindrome, then print NO as printf. Note that the words
YES/NO
have to be in UPPERCASE (capital letters). Other than the words YES or NO, no other extra
information should be printed to Printf.
Sample Input
53435
Sample Output
N=53435
Yes
Testcase 1
Input
53435
Output
N=53435
Yes
Testcase 2
Input
56
Output
N=56
No
Testcase 3
Input
12345
Output
N=12345
No
Testcase 4
Input
123321
Output
N=123321
Yes
Testcase 5
Input
8732
Output
N=8732
No
Testcase 6
Input
146641
Output
N=146641
Yes
Testcase 7
Input
84216
Output
N=84216
No
Testcase 8
Input
24698
Output
N=24698
No

Write a program that will find the sum of all prime no. in a given range. The range will
be specified. The
first line contains, N1 which is a positive integer, will contain the lower bound of the range.
The second
line N2, which is also a positive integer, will contain the upper bound of the range. The
program should
consider all the prime no. within the range, excluding the upper and lower bound in the
output in
integer format to stdout. Other than the integer number ,no other extra information should be
printed
to stdout. Other than the integer number ,no other extra information should be printed to
stdout
Example: input “7” and “24”, here N1=7 and N2=24, expected output is 83
Sample input
7 24
Sample output
Enter the start and end value: 7 24
83
Testcase 1
Input
7 24
Output
Enter the start and end value: 7 24
83
Testcase 2
Input
28
Output
Enter the start and end value: 2 8
15
Testcase 3
Input
12 40
Output
Enter the start and end value: 12 40
169
Testcase 4
Input
23 76
Output
Enter the start and end value: 23 76
612
Testcase 5
Input
4 33
Output
Enter the start and end value: 4 33
155
Testcase 6
Input
3 21
Output
Enter the start and end value: 3 21
72
Testcase 7
Input
23 55
Output
Enter the start and end value: 23 55
281
Testcase 8
Input
1 10
Output
Enter the start and end value: 1 10
17

Write a program to add two numbers and converting the result to binary
This is a C program to Find the Sum of two Binary Numbers.
Problem Description
This program finds the sum of two binary numbers.
Problem Solution
1. Take two binary numbers as input.
2. Add each bits from the two binary numbers separately starting from LSB.
3. The operations may be as follows.
a) (0+0)=0,
b) (1+0)=1,
c) (1+1)=0 and 1 will be remainder.
Sample input
1000
1101
Sample output
Enter the first binary number:1000
Enter the second binary number:1101
Sum of two binary numbers:10101
Testcase 1
Input
1000
1101
Output
Enter the first binary number:1000
Enter the second binary number:1101
Sum of two binary numbers:10101
Testcase 2
Input
1010
1100
Output
Enter the first binary number:1010
Enter the second binary number:1100
Sum of two binary numbers:10110
Testcase 3
Input
1111
0101
Output
nter the first binary number:1111
Enter the second binary number:0101
Sum of two binary numbers:10100
Testcase 4
Input
10
11
Output
Enter the first binary number:10
Enter the second binary number:11
Sum of two binary numbers:101
Testcase 5
Input
1
01
Output
Enter the first binary number:1
Enter the second binary number:01
Sum of two binary numbers:10
Testcase 6
Input
1001
0110
Output
Enter the first binary number:1001
Enter the second binary number:0110
Sum of two binary numbers:1111
Testcase 7
Input
10111
11001
Output
Enter the first binary number:10111
Enter the second binary number:11001
Sum of two binary numbers:110000
Testcase 8
Input
10
01
Output
Enter the first binary number:10
Enter the second binary number:01
Sum of two binary numbers:11

Write a program to check for armstrong number


Sample input
1634
Sample output
Enter an integer: 1634
1634 is an Armstrong number
Testcase1
Input
1634
Output
Enter an integer: 1634
1634 is an Armstrong number
Testcase2
Input
2017
Output
Enter an integer: 2017
2017 is not an Armstrong number
Testcase3
Input
1632
Output
Enter an integer: 1632
1632 is not an Armstrong number
Testcase4
Input
1632
Output
Enter an integer: 1998
1998 is not an Armstrong number
Testcase5
Input
1632
Output
Enter an integer: 371
371 is an Armstrong number
Testcase6
Input
1456
Output
Enter an integer: 1456
1456 is not an Armstrong number
Testcase7
Input
407
Output
Enter an integer: 407
407 is an Armstrong number
Testcase8
Input
432
Output
Enter an integer: 432
432 is not an Armstrong number

Write a program to check for perfect number


This C Program checks whether a given number is perfect number. Perfect number is
a number which is equal to sum of its divisor. For eg,divisors of 6 are 1,2 and 3. The
sum of these divisors is 6. So 6 is called as perfect number.
Sample input
6
Sample output
Enter a Number
6
perfect number
Testcase 1
Input
6
Output
Enter a Number
6
perfect number
Testcase 2
Input
32
Output
Enter a Number
32
Not a perfect number
Testcase 3
Input
25
Output
Enter a Number
25
Not a perfect number
Testcase 4
Input
12
Output
Enter a Number
12
Not a perfect number
Testcase 5
Input
28
Output
Enter a Number
28
perfect number
Testcase 6
Input
53
Output
Enter a Number
53
Not a perfect number
Testcase 7
Input
8128
Output
Enter a Number
8128
perfect number
Testcase 8
Input
7523
Output
Enter a Number
7523
Not a perfect number

Write a program to check if input string is palindrome or not


Problem Description
The program takes a string and checks if a string is a palindrome or not.
Problem Solution
1. Take a string from the user and store it in a variable.
2. Reverse the string using string slicing and compare it back to the original
string.
3. Print the final result
4. Exit.
Sample input
wow
Sample output
Enter a string: wow
wow is a palindrome
Testcase1
Input
wow
Output
Enter a string: wow
wow is a palindrome
Testcase2
Input
test
Output
Enter a string: test
test is not a palindrome
Testcase3
Input
mom
Output
Enter a string: mom
mom is a palindrome
Testcase4
Input
school
Output
Enter a string: school
school is not a palindrome
Testcase5
Input
momo
Output
Enter a string: momo
momo is not a palindrome
Testcase6
Input
madam
Output
Enter a string: madam
madam is a palindrome
Testcase7
Input
123321
Output
Enter a string: 123321
123321 is a palindrome
Testcase8
Input
string
Output
Enter a string: string
string is not a palindrome

Write a program to find the area of a triangle given the base and the corresponding
height. The values
base and height are both positive integers passed to the program respectively. Write the
output to
stdout formatted as a floating point number rounded to EXACTLY 2 decimal precision
WITHOUT any
other additional text. Scientific format(such as 1.00E+5) should NOT be used while printing
the output.
You may assume that the inputs will be such that the output will not exceed the largest
possible real
number that can be stored in a float type variable.
Sample input
33
31
Sample output
511.50
Testcase 1
Input
33
31
Output
511.50
Testcase 2
Input
10
20
Output
100.00
Testcase 3
Input
243
12
Output
1458.00
Testcase 4
Input
43
32
Output
688.00
Testcase 5
Input
263
104

You might also like