0% found this document useful (0 votes)
2 views2 pages

Coding Test Set 1

The document outlines a coding test set consisting of various programming tasks, including displaying prime numbers within intervals, calculating the power of a number, summing natural numbers, and generating specific sequences. Each task includes test cases with inputs, expected outputs, and the logic being tested. The tasks range from basic functionality to more complex sequences, ensuring comprehensive coverage of programming concepts.
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)
2 views2 pages

Coding Test Set 1

The document outlines a coding test set consisting of various programming tasks, including displaying prime numbers within intervals, calculating the power of a number, summing natural numbers, and generating specific sequences. Each task includes test cases with inputs, expected outputs, and the logic being tested. The tasks range from basic functionality to more complex sequences, ensuring comprehensive coverage of programming concepts.
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

Coding Test Set 1

1. Write a program to display prime numbers between two intervals.


Test Case Input Expected Output Logic Tested
Range
Standard 10 30 11 13 17 19 23 29 Normal functionality.
Range
Start with 1 1 10 2357 Ensures 1 is correctly excluded (1 is not prime).
No Primes 8 10 No prime numbers Checks range where only composite numbers
found exist.
Negative Range -5 5 235 Ensures negative numbers and zero are ignored.
Single Prime 13 13 13 Checks if the boundaries are inclusive.
Large Gap 90 100 97 Tests efficiency near the end of the century.

2. Write a program to calculate the power of a number.


Test Case Base Exponent Expected Output Logic Tested
Positive Integer 2.0 3 8.0000 Standard multiplication.
Zero Exponent 5.5 0 1.0000 Any number to power 0 is 1.
Negative Exponent 2.0 -2 0.2500 Reciprocal calculation (1/(2^2)).
Base is Zero 0.0 5 0.0000 0 raised to any positive power is 0.
Base is One 1.0 100 1.0000 1 raised to any power is 1.
Negative Base -3.0 2 9.0000 Squaring a negative results in a positive.

3. Write a program to calculate the sum of n natural numbers.


Test Case Input (n) Expected Output Logic Tested
Standard Input 10 55 General logic (1+2+...+10).
Zero Case 0 0 Sum of zero numbers is zero.
Smallest Natural 1 1 Checks if the loop handles the lower boundary.
Large Input 1000 500500 Checks if the variable can hold larger sums.
Negative Input -5 Error message Validates that the program only accepts positive integers.

4. Write a program to find the sum of first n prime numbers.


Test Case Input (n) Primes Included Expected Logic Tested
Output
Small n 3 2, 3, 5 10 Basic count and sum logic.
Standard n 5 2, 3, 5, 7, 11 28 Checks multiple iterations.
First 1 2 2 Boundary check for the smallest
Prime input.
Zero Case 0 None 0 Ensures loop doesn't run if n=0.
Larger n 10 2, 3, 5, 7, 11, 13, 17, 19, 129 Verifies accuracy across 10 primes.
23, 29
5. Write a program to display the sequence 1, 4, 9, 16, 25, 36, 49,………………..
6. Write a program to display the sequence 1, 2, 4, 8, 16, 32, 64,………………..
7. Write a program to display the sequence 7, 10, 8, 11, 9, 12, .................
8. Write a program to display the sequence 1, 2, 4, 7,11,……………
9. Write a program to display the sequence 1, 1, 5, 5, 9, 9, 13, 13, ………………………..
10. Write a program to display the sequence 21, 9, 21, 11, 21, 13, 21, .................
11. Write a program to display the sequence 14, 28, 20, 40, 32, 64, ...………………..
12. Write a program to display the sequence A1, B2, C4, D8, E16, F32, .................
13. Write a program to display the sequence A1, B2, C3, …., Y25,Z26, A1, B2,……………
14. Write a program to display the sequence A, Z, X, B, V,……………………
15. Write a program to display the sequence BCA1, BCB2, BCC3, BCD4, …………………
16. Write a program to display the sequence AMM, COO, EQQ,……….
17. Write a program to display the sequence ABA, BCB, CDC, DED, ……………….
18. Read a number from STDIN, then display the sequence given below:
Input: 52934
Output: A5, B2, C9, D3, E4
19. Write a program to display the sequence 1, 2, 2, 4, 8, 32, 256,………………..
20. Write a program to display the series 0,0,2,1,4,2,6,3,8,4,……………………….

You might also like