Assignment Set-23
Assignment Set-23
1. Write a C programme that reads an integer and prints another integer that is the reverse of
the input. For example, let the input be 932345, the programme will output 543239.
2. Write a C programme that reads an integer and prints the positional value of the digits. For
example, let the input be 5431, the programme will output
5000
400
30
1
3. Write a C programme to compute the factorial of n. For example, let n=5, the programme
will output 120 (i.e., 1x2x3x4x5 = 120).
4. Write a C programme that reads three integers and prints the middle valued integer.
5. Write a C programme that reads two integers A and B. Use switch-case block to computer
a. Summation of A, B
b. Subtraction of A, B
c. Multiplication of A, B
d. Division of A, B (check the divisor is not equals to ZERO)
𝑓 = 2 + 22 + 23 + ⋯ 𝑛 𝑡𝑒𝑟𝑚𝑠
𝑓 (𝑥, 𝑦) = 2𝑥 + 2𝑥−1 + ⋯ + 3𝑦+2 + 3𝑦+1 + 3𝑦 , for all exponents of 2 are greater or equal than the
exponents of 3. Read x and y from the user. (For example: inputting x = 6 and y = 2 we have to
evaluate 26 + 25 + 24 + 34 + 33 + 32 )
3 Write a C Programme to compute the LCM of two numbers. Use the for to implement the LCM
Programme.
XXXX
XXXX
XXXX
XXXX
4. Print the diamond of sixe 2N as below. The input to the program is N.
X
XXX
XXXXX
XXXXXXX
XXXXXXX
XXXXX
XXX
X
Algorithm:
1. FOR(I = 1 to N)
2. FOR(J =1 to N-I)
3. Print blank
4. FOR(J=1 to 2I-1)
5. Print ‘X’
6. FOR(I = 1 to N)
7. FOR(J =1 to I-1)
8. Print blank
9. FOR(J=1 to 2(N-1)+1)
10. Print ‘X’
5. List the numbers within 100 to 200 whose sum of the digits are prime. Example : 100,
101,102,104, 106,110,111,…………………………..
Computer Programming Laboratory (Section F)
𝑓 = 1 + (1 + 2) + ⋯ + (1 + 2 + ⋯ + 10)
2
∑(𝑥𝑖 − 𝑥̅ )
𝑠𝑑 = √
𝑁 −1
8. Write a C Program that reads N integers in an array then moves all odd integers towards the
left and even integers towards the right. Below id the algorithm and a working example.
3 6 5 4 3 4 1 4
Algorithm:
1. Read the array A of size N.
2. Set I = 0, J = N-1.
3. WHILE(I <= J)
a. IF( A[I] is even)
i. WHILE(A[J] not an odd)
J=J–1
b. SWAP A[I], A[J]
c. I = I + 1;
3 1 5 4 3 4 6 4
I=1, J = 6 and SWAP
I=2, J = 6
I=3, J = 6
I=3, J = 5
3 1 5 3 4 4 6 4
I=3, J = 4 and SWAP
I=4, J=4
I=5, J=4 TREMINATES
Computer Programming Laboratory (Section F)
4. Write a C Program that reads an integer array (all elements are greater than Zero) and
counts the occurrence of each number. For example, if the input is
3 7 4 7 2 3 5 7 4 1
The Program will produce the output as:
3 occurs 2 times
7 occurs 3 times
4 occurs 2 times
2 occurs 1 times
5 occurs 1 times
1 occurs 1 times
Algorithm:
1. Declare different pointer variables (e.g., void, char, short, int, float,
double) and demonstrate the offset operation on each of the pointer variables.
Example: Let ip is an integer pointer pointing to an integer x. Show the value of ip and ip
offset to 1 (i.e., ip+1).
2. Declare two integer arrays of size 10 and an integer pointer. Access the arrays using the
pointer variable.
3. Implement the linear search using the pointer variable. Use dynamic memory allocation
instead of declaring an array.
#include<stdlib.h>
void* malloc(int size);
4. Implement the binary search using the pointer variable. Use dynamic memory allocation
instead of declaring an array.
#include<stdlib.h>
void* malloc(int size);
Computer Programming Laboratory (Section F)
1. String Length:
- Write a program that prompts the user to enter a string. The program should then display
the length of the string entered by the user.
2. String Concatenation:
- Develop a program that asks the user to input two separate strings.
- The program should then concatenate (join) these strings and display the result.
3. String Comparison:
- The program should compare these strings and output, whether they are exactly the same
or not.
4. String Reversal:
- The program should then output the reverse of the input string.
5. Substring match:
- Design a program that first takes a longer string as input from the user. Then, it should ask
the user to enter a shorter string.
- The program needs to determine if the shorter string is a substring of the longer string and
inform the user of the result.