[go: up one dir, main page]

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

Assignment Set-23

The document contains a series of programming assignments for a Computer Programming Laboratory, focusing on C programming tasks. Assignments include writing programs for integer manipulation, mathematical computations, string operations, and array handling. Each set of problems progressively builds on programming concepts such as loops, functions, and pointer usage.

Uploaded by

Ashish Sagar
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 views7 pages

Assignment Set-23

The document contains a series of programming assignments for a Computer Programming Laboratory, focusing on C programming tasks. Assignments include writing programs for integer manipulation, mathematical computations, string operations, and array handling. Each set of problems progressively builds on programming concepts such as loops, functions, and pointer usage.

Uploaded by

Ashish Sagar
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/ 7

Computer Programming Laboratory (Section F)

Problem Assignment SET - 2

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)

The switching of the operations would be on the choice of character a, b, c, and d,


respectively.
Computer Programming Laboratory (Section F)

Problem Assignment SET - 3

6. Write a C Programme to compute the following series of n-terms

𝑓 = 2 + 22 + 23 + ⋯ 𝑛 𝑡𝑒𝑟𝑚𝑠

𝑓(𝑥) = 𝑥 + 2𝑥 2 + 3𝑥 3 + ⋯ 𝑛 𝑡𝑒𝑟𝑚𝑠 , Input the degree n and the variable x

𝑓 (𝑥, 𝑦) = 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 )

7. Write a C Programme to compute the GCD of two numbers.


i) Let A and B be the two number and A >B.
ii) Write a for loop with variable i = B and decrement by i = i – 1
iii) Check whether i divides both A and B. If so, i would be the GCD.

3 Write a C Programme to compute the LCM of two numbers. Use the for to implement the LCM
Programme.

i. Let A and B be the two number and A>B.


ii. Write a for loop with variable i = A and j = 1. Increase A with its multiples.
iii. Check whether B divides the multiples of A. If so, that would be the LCM.
Computer Programming Laboratory (Section F)

Problem Assignment SET - 4

1. Find the Greatest Common Divisor of two number.


Algorithm:
1 Read two numbers A and B
2 IF ( B >A)
a. Swap A, B // use temporary variable for swapping
3 WHILE( A % B not equals to 0)
a. Temp = B
b. B = A%B
c. A = Temp
4 Print B
2. Using nested loop compute the function
𝑓 (𝑁) = 1 + (1 + 2) + (1 + 2 + 3) + ⋯ + (1 + 2 + 3 + ⋯ + 𝑁)
3. Print the rhombus of size N as below

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)

Problem Assignment SET - 5

6. Write a C Program that reads an array A as below:


1 2 3 4 5 6 7 8 9 10
 Now write a loop that updates the A[I] cell as the sum of A[I-1] + A[I] cell element
(except the 0th cell). Do the update from left to right.
 Now add all elements of the array.
 Check whether the content of cell A[I] is the evaluation of function

𝑓 = 1 + (1 + 2) + ⋯ + (1 + 2 + ⋯ + 10)

7. Write a C Program to compute the standard deviation of N integer elements.


Use an integer array of size N to store the elements.

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;

The program updates the array as below:


I=0, J = 7
I=1, J = 7

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. Read the array in A.


2. Set I = 0
3. For I = 0 to the size of the Array
a. If A[I] is not Zero
b. Set Count = 1
c. Check how many A[I] are appearing towards the RIGHT, increase the Count
accordingly and Replace the instances with Zero.
d. Print the Count.
e. Reset the Count to Zero.
Computer Programming Laboratory (Section F)

Problem Assignment SET – 6

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)

Problem Assignment SET-7:

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:

- Create a program that requests two strings from the user.

- The program should compare these strings and output, whether they are exactly the same
or not.

4. String Reversal:

- Write a program that asks the user to input a string.

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

You might also like