0% found this document useful (0 votes)
13 views14 pages

C Programs With Test Cases (Set 2)

The document describes 15 problems to solve using C programming. Each problem includes test cases for valid and invalid inputs, and specifications for the expected output format. The problems cover a range of tasks including adding and multiplying numbers, finding data types sizes, checking number properties like even/odd, and calculating sequences. The common aspects across all problems are the restrictions on input format, expected error message for invalid inputs, and requirement to print outputs without additional text.

Uploaded by

bhslegion1498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

C Programs With Test Cases (Set 2)

The document describes 15 problems to solve using C programming. Each problem includes test cases for valid and invalid inputs, and specifications for the expected output format. The problems cover a range of tasks including adding and multiplying numbers, finding data types sizes, checking number properties like even/odd, and calculating sequences. The common aspects across all problems are the restrictions on input format, expected error message for invalid inputs, and requirement to print outputs without additional text.

Uploaded by

bhslegion1498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Problem 1: C program to add two integers.

Test Cases:

-----------

1. VALID INPUT:

a) Only 2 Integer will be given as input.You may assume that the input integer will be such that
the output will not exceed the largest possible integer that can be stored in an int type variable.

2. INVALID INPUTS:

a) no commandline argument.

b) fraction

c) string

d) more than two command line arguments

e) one command line argument

3. OUTPUT:

a) Print only the result of the addition to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
========

Problem 2: C program to multiply two floating point numbers.

Test Cases:

-----------

1. VALID INPUT:

a) Only 2 floating point number will be given as input.You may assume that the input number
will be such that the output will not exceed the largest possible floating point number that can be stored
in an float type variable.
2. INVALID INPUTS:

a) no commandline argument.

b) one command line argument

c) string

d) more than two command line arguments

3. OUTPUT:

a) 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.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
===============

Problem 3: C program to find size of int, float, double and char.

1.OUTPUT:

a) Write the size of int, float, double and char to the STDOUT seperated by a space without any
other additional text.

=====================================================================================
===============

Problem 4: C program to check whether a number is even or odd.

Test Cases:

-----------

1. VALID INPUT:

a) Only positive Integer will be given as input.

(Consider 0 as an even number)


2. INVALID INPUTS:

a) -5

b) fraction

c) string

d) two or more command line arguments

e) no command line argument

3. OUTPUT:

a) If the number is even print 'EVEN' to the STDOUT without any other additional text.

b) If the number is 'ODD' to the STDOUT without any other additional text and terminate.

c) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
==================

Problem 5: C program to check whether a Character is Vowel or consonant.

Test Cases:

-----------

1. VALID INPUT:

a) Only one Character will be given as input.

2. INVALID INPUTS:

a) Numbers

b) More than one character

c) two or more command line arguments

d) no command line argument

3. OUTPUT:

a) If the chracter is vowel print 'VOWEL' to the STDOUT without any other additional text.

b) If the character is consonant print 'CONSONANT' to the STDOUT without any other additional
text and terminate.
c) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
=================

Problem 6: C program to find largest among 3 numbers.

Test Cases:

-----------

1. VALID INPUT:

a) Only three Integer will be given as input.

2. INVALID INPUTS:

a) no command line argument

b) string

c) two or more than three command line argument

3. OUTPUT:

a) Print only the highest number to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
=================

Problem 7: C program to find ASCII value of a character.

Test Cases:

-----------

1. VALID INPUT:

a) Only character will be given as input.

2. INVALID INPUTS:

a) No command line argument.

b) More than one character


3. OUTPUT:

a) Print only the ASCII value to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
========================

Problem 8: C program to check whether a character is alphabet or not.

Test Cases:

-----------

1. VALID INPUT:

a) Only character will be given as input.

2. INVALID INPUTS:

a) No command line argument.

b) More than one character

3. OUTPUT:

a) If it is alphabet print 'Y' to the STDOUT without any other additional text.

b) If it is not alphabet print 'N' to the STDOUT without any other additional text.

c) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
=========

Problem 9: C program to find largest among 3 numbers.

Test Cases:

-----------

1. VALID INPUT:

a) Only three Integer will be given as input.


2. INVALID INPUTS:

a) no command line argument

b) string

c) two or more than three command line argument

3. OUTPUT:

a) Print only the highest number to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
=========

Problem 10: C program to check whether a number is even or odd.

Test Cases:

-----------

1. VALID INPUT:

a) Only positive Integer will be given as input.

(Consider 0 as an even number)

2. INVALID INPUTS:

a) -5

b) fraction

c) string

d) two or more command line arguments

e) no command line argument

3. OUTPUT:

a) If the number is even print 'EVEN' to the STDOUT without any other additional text.

b) If the number is 'ODD' to the STDOUT without any other additional text and terminate.

c) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.
=====================================================================================
======

Problem 11: C program to check whether number is positive or negative.

Test Cases:

-----------

1. VALID INPUT:

a) Only Integer will be given as input.

2. INVALID INPUTS:

a) two or more command line arguments

b) no command line argument

c) string

3. OUTPUT:

a) If the number is Positive print 'POSITIVE' to the STDOUT without any other additional text.

b) If the number is 'NEGATIVE' to the STDOUT without any other additional text and terminate.

c) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
=====

Problem 12: C program to calculate sum of natural numbers up to a certain number.

If the input is 7 then you have to calculate the sum 1+2+3+4+5+6+7=28

Test Cases:

-----------

1. VALID INPUT:

a) Only one positive Integer(greater than 0) will be given as input.

2. INVALID INPUTS:

a) -5

b) fraction
c) string

d) two or more command line arguments

e) no command line argument

3. OUTPUT:

a) Print only the sum to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
=====

Problem 13: C program to generate multiplication table of a number.

If the input is 9 OUTPUT will be like follows without any other additional text.

9*1=9

9 * 2 = 18

9 * 3 = 27

9 * 4 = 36

9 * 5 = 45

9 * 6 = 54

9 * 7 = 63

9 * 8 = 72

9 * 9 = 81

9 * 10 = 90

=================================================================================

Problem 14: C program to display Fibonacci sequence upto N number.

If the input is 7 then you have to calculate the output will be 0 1 1 2 3 5

Test Cases:

-----------
1. VALID INPUT:

a) Only one positive Integer(greater than 0) will be given as input.

2. INVALID INPUTS:

a) -5

b) fraction

c) string

d) two or more command line arguments

e) no command line argument

3. OUTPUT:

a) Print only the terms seperated by a space to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

================================================================================

Problem 15: C program to display Fibonacci sequence upto N terms.

If the input is 7 then you have to calculate the output will be 0 1 1 2 3 5 8

Test Cases:

-----------

1. VALID INPUT:

a) Only one positive Integer(greater than 0) will be given as input.

2. INVALID INPUTS:

a) -5

b) no command line argument

c) string

d) two or more command line arguments

3. OUTPUT:

a) Print only the terms seperated by a space to the STDOUT without any other additional text.
b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
======

Problem 16: C program to find GCD and LCM of N number

Test Cases:

-----------

1. VALID INPUT:

a) Only positive Integers(greater than 0) will be given as input.

2. INVALID INPUTS:

a) -5

b) no command line argument

c) string

3. OUTPUT:

a) Print GCD and LCM seperated by a space to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
======

Problem 17: C program to find GCD using recursion

Test Cases:

-----------

1. VALID INPUT:

a) Only positive Integers(greater than 0) will be given as input.

2. INVALID INPUTS:

a) -5

b) no command line argument


c) string

3. OUTPUT:

a) Print GCD to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================
=====

Problem 18: C program to count no of digits in an integer.

Test Cases:

-----------

1. VALID INPUT:

a) Only one positive Integer(greater than 0) will be given as input.

2. INVALID INPUTS:

a) -5

b) fraction

c) string

d) two or more command line arguments

e) no command line argument

3. OUTPUT:

a) Print only the number of digits to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================

Problem 19: C program to reverse a number.

Test Cases:

-----------

1. VALID INPUT:
a) Only one positive Integer(greater than 0) will be given as input.

2. INVALID INPUTS:

a) -5

b) fraction

c) string

d) two or more command line arguments

e) no command line argument

3. OUTPUT:

a) Print only the reverse number to the STDOUT without any other additional text.

b) In case of invalid input print 'ERROR' to the STDOUT without any other additionl text and
terminate.

=====================================================================================

Problem 20: C program to compute quotient and remainder.

Test Cases:

-----------

1. VALID INPUT:

a) Only Integer will be given as input.

Input Example (blnank space seperated): 20 2

<dividend> <divisor>

2. INVALID INPUTS:

a) 5

b) fraction

c) string

d) 0 as divisor

e) one command line arguments

3. You should generate output as follows::


a) Only the Quotient and Remainder (Blank space seperated) of the input numbers should be printed
to the STDOUT without any other additional text. example : [if input is] 20 2

[then the out output should be ] 10 0

b) For any invalid input or error print ERROR to the STDOUT without any other additional text and
terminate.

=====================================================================================

Problem 21. C program to display characters from A to Z using loop

Test Cases:

-----------

1. Run the program without any argument.

2. You should generate output as follows::

a) A to Z without any additional text.

=============================================================================

Problem 22: C program to make a simple calculator using switch case. Input numbers will be given as
integer(no floating point numbers) and in such a way that there will be no overflow in result.

Test Cases:

---------------

1. VALID INPUT: [format (infix notation only) i.e. 5 + 4; operand1(5) operator(+) operand2(4) without any
other extra text/characters. Output will be only 9. No extra characters/text.

a) any characters '0-9' & '-', '+', '/', '*'

e.g. ./a.out 9 * 10

OUTPUT: 90

2. INVALID INPUTS:

a) 7/0 => E

b) fraction

c) string
3. You should generate output as follows::

For any invalid input or error print E to the STDOUT without any other additional text and terminate.

===========================================================================

You might also like