Cpp
Cpp
Solution:
#include <stdio.h>
int main() {
int M, N;
int isUpper = 1;
scanf("%d", &M);
printf("Enter number of columns (N): ");
scanf("%d", &N);
if (M != N) {
return 0;
int matrix[M][N];
scanf("%d", &matrix[i][j]);
if (matrix[i][j] != 0) {
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
isUpper = 0;
break;
}
if (!isUpper)
break;
// Result
if (isUpper)
else
return 0;
Output :
Enter number of rows (M): 3
Enter number of columns (N): 3
Enter elements:
123
056
009
Objective : A c program that reads two square matrices of order M × M, subtracts the
second matrix from the first, and displays the resultant matrix.
Solution :
#include <stdio.h>
int main() {
int M;
scanf("%d", &M);
scanf("%d", &matrix1[i][j]);
scanf("%d", &matrix2[i][j]);
}
printf("\nResultant Matrix after Subtraction (matrix1 - matrix2):\n");
printf("%d\t", result[i][j]);
printf("\n");
return 0;
Output :
Enter the order of the square matrices (M): 2
matrix1[0][0]: 5
matrix1[0][1]: 7
matrix1[1][0]: 3
matrix1[1][1]: 9
matrix2[0][0]: 2
matrix2[0][1]: 1
matrix2[1][0]: 1
matrix2[1][1]: 4
2 5
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Problem Statement 03: Develop a C program to read a square matrix M x M &
then find the sum of the elements around the peripheral. Display their final sum to
the console.
Objective: To compute the sum of all elements located on the border (peripheral)
of a square matrix.
Solution:
#include <stdio.h>
int main() {
int M, sum = 0;
scanf("%d", &M);
int matrix[M][M];
scanf("%d", &matrix[i][j]);
sum += matrix[i][j];
return 0;
}
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Output:
Enter the order of the square matrix (M): 3
Enter elements:
123
456
789
Problem Statement 04: Develop a C program to accept the names in a 2-D array and then
search a name entered by the user. Display an appropriate message to the output screen if found.
Objective : To accept multiple names into a 2-D character array and allow the user to
search for a specific name.
Solution :
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 50
int main() {
int n, found = 0;
char names[MAX_NAMES][MAX_LENGTH];
char searchName[MAX_LENGTH];
scanf("%d", &n);
getchar();
if (strcmp(names[i], searchName) == 0) {
found = 1;
break;
if (found) {
} else {
return 0;
}
Output :
Enter the number of names: 3
Name 1: Alice
Name 2: Bob
Name 3: Charlie
Problem Statement 05 : Develop a C program to read two square binary matrices of order
N x N from the user and perform the XOR on the elements of the matrices and print the resultant
matrix to the output screen.
Objective : To read two square binary matrices of order N × N from the user, perform a
bitwise XOR operation on corresponding elements of the matrices, and display the resultant
matrix.
Solution :
#include <stdio.h>
int main() {
int N;
scanf("%d", &N);
scanf("%d", &matrix1[i][j]);
scanf("%d", &matrix2[i][j]);
}
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
}
printf("\n");
return 0;
Output :
Enter the order of the square binary matrices (N): 2
10
01
11
01
01
00
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Problem Statement 06 : Design a UDF that returns the by swapping all the elements
about the principal diagonal of a matrix. Develop a C program to implement the function by
accepting the rows and columns in the main program. Display the swapped matrix in the
calling program.
Objective : To create a user-defined function that swaps all elements about the principal
diagonal of a square matrix, and then displays the modified matrix from the main (calling)
program.
Solution :
#include <stdio.h>
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
int main() {
int matrix[MAX][MAX];
int n;
scanf("%d", &n);
scanf("%d", &matrix[i][j]);
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
}
}
swapAboutDiagonal(matrix, n);
printf("\n");
}
return 0;
Objective:
Enter the order of the square matrix (n x n): 3
matrix[0][0]: 1
matrix[0][1]: 2
matrix[0][2]: 3
matrix[1][0]: 4
matrix[1][1]: 5
matrix[1][2]: 6
matrix[2][0]: 7
matrix[2][1]: 8
matrix[2][2]: 9
147
258
369
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Problem Statement 07: Write a C program to read a sentence from the user and replace
all the occurrences of vowels with a X character. Display the modified string to the console.
Objective : C program that reads a sentence from the user, replaces all vowels (a, e, i, o, u
in both lowercase and uppercase) with the character 'X', and displays the modified string.
Solution :
#include <stdio.h>
#include <string.h>
int main() {
char sentence[200];
char ch = sentence[i];
sentence[i] = 'X';
}
return 0;
}
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Output :
Enter a sentence: Hello World, how are you?
Modified sentence: HXllX WXrld, hXw XrX yXX?
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Problem Statement 08: Develop a C program to concatenate two strings and display the
concatenated string to the output screen without using the inbuilt function.
Objective : C program that concatenates two strings without using any built-in functions like
strcat() from <string.h>. It manually appends the second string to the end of the first string and
then displays the result.
Solution :
#include <stdio.h>
int main() {
str1[i] = '\0';
break;
i++;
if (str2[j] == '\n') {
str2[j] = '\0';
}
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
str1[i] = str2[j];
i++;
j++;
str1[i] = '\0';
return 0;
Output :
Enter the first string: Hello
Problem Statement 09 : Write a C program that accepts a main string along with a
starting position and ending position of a substring to be extracted from the user in the main
program. Print the extracted string in the calling program.
Solution :
#include <stdio.h>
int j = 0;
subStr[j++] = mainStr[i];
subStr[j] = '\0';
int main() {
if (mainStr[i] == '\n') {
mainStr[i] = '\0';
break;
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
}
scanf("%d", &start);
scanf("%d", &end);
return 0;
Objective:
Problem Statement 10: Develop a C program to compare two strings using a UDF and
return 1 if the strings are equal and 0 otherwise without using the built-in function strcmp().
Display an appropriate message to the output screen.
Objective : Here's a C program that compares two strings using a User-Defined Function
(UDF) without using the built-in strcmp() function. It returns 1 if the strings are equal, and 0
otherwise, then displays an appropriate message.
Solution :
#include <stdio.h>
int i = 0;
if (str1[i] != str2[i]) {
i++;
}
return 1;
} else {
return 0;
}
int main() {
int result;
if (str1[i] == '\n') {
str1[i] = '\0';
break;
if (str2[i] == '\n') {
str2[i] = '\0';
break;
if (result == 1) {
} else {
printf("The strings are NOT equal.\n");
return 0;
Output:
Enter the first string: Hello
Problem Statement 11: Develop a C program to find the number of occurrences of each
alphabet in a string accepted from the user and display the same to the output screen. Assume
that the string contains only alphabets.
Objective: Here's a C program that counts the number of occurrences of each alphabet (A–
Z or a–z) in a string entered by the user. The program assumes that the string contains only
alphabetic characters and is case-insensitive (i.e., treats 'A' and 'a' as the same).
Solution :
#include <stdio.h>
int main() {
char str[200];
char ch = str[i];
count[ch - 'A']++;
count[ch - 'a']++;
}
}
if (count[i] > 0) {
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
printf("%c = %d\n", i + 'A', count[i]);
}
}
return 0;
Output:
Enter a string (alphabets only): HelloWorld
D=1
E=1
H=1
L=3
O=2
R=1
W=1
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Problem Statement 12: Write a C program to accept the string from the user and then
reverse string without using the second string.
Objective : Here's a C program to reverse a string in place, i.e., without using a second
string or any library functions like strrev().
Solution :
#include <stdio.h>
int main() {
char str[200];
int length = 0, i = 0;
if (str[length] == '\n') {
str[length] = '\0';
break;
}
length++;
int start = 0;
char temp;
str[start] = str[end];
str[end] = temp;
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
start++;
end--;
return 0;
Output :
Enter a string: HelloWorld
Problem Statement 13: Design a UDF in C to find the product and quotient of two
numbers passed to it from the calling program. Display the product and the quotient in the
main program. Read the two numbers in the main program & also display their product and
quotient. Implement using a pointer.
Objective : Here's a C program that uses a User Defined Function (UDF) to calculate the
product and quotient of two numbers passed from the main function. The function uses
pointers to return both results back to the main program.
Solution :
#include <stdio.h>
*product = a * b;
if (b != 0) {
*quotient = a / b;
} else {
}
}
int main() {
scanf("%f", &num1);
scanf("%f", &num2);
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
if (num2 != 0) {
return 0;
Output :
Enter the first number: 10
Quotient: 2.00
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Problem Statement 14: Write a C program to accept & store N real numbers into an array.
Find their mean and standard deviation using pointers and display the same to the output screen.
Objective : Here is a C program that:
Solution :
#include <stdio.h>
#include <math.h>
return sum / n;
int main() {
int n;
float numbers[100];
scanf("%d", &n);
return 1;
scanf("%f", &numbers[i]);
return 0;
Output :
1.0
2.0
3.0
4.0
5.0
Mean = 3.00
Problem Statement 15: Write a C program to accept N integers from the user into an
array. If any integer is positive then subtract 2 from it, if integer is negative add 1 to it and if
zero then do nothing. Implement a UDF using a pointer to perform these operations and
finally display the modified array to the screen in the calling program.
Objective: Here's a C program that accepts N integers from the user, modifies the integers
based on their value (positive, negative, or zero), and displays the modified array. The core
logic is implemented in a User Defined Function (UDF) that uses pointers.
Solution:
#include <stdio.h>
if (*(arr + i) > 0) {
*(arr + i) -= 2;
*(arr + i) += 1;
}
// If zero, do nothing
int main() {
int N;
scanf("%d", &N);
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
int arr[N]; // Declare array of size N
scanf("%d", &arr[i]);
printf("Modified array:\n");
return 0;
Output :
Enter the number of integers (N): 6
Enter 6 integers:
5 -3 0 8 -1 2
Modified array:
3 -2 0 6 0 0
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
Problem Statement 16: Design a UDF using pointer that returns 1 if the string is a
palindrome otherwise zero. Accept a string from user in the calling program. Display an
appropriate message in the calling program. Implement a C program for the same. Ignore the
case.
Solution:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
if (tolower(*start) != tolower(*end)) {
start++;
end--;
return 1; // Palindrome
}
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
int main() {
char str[100];
if (isPalindrome(str)) {
} else {
return 0;
Output:
Enter a string: Madam
Problem Statement 17: Design a UDF that returns the count of special characters
present in a sentence passed to it using pointer to the calling program. Implement a C
program to read a string in the main program and display all the count of the special
characters returned by the function to the console.
Objective: Here's a C program that counts the number of special characters in a string
using a User Defined Function (UDF). The function uses pointers and returns the count to the
calling program.
Solution:
#include <stdio.h>
#include <ctype.h>
int count = 0;
count++;
}
return count;
int main() {
char sentence[200];
// Display result
return 0;
Output :
Enter a sentence: Hello, World! @2025
Problem Statement 18: Design a UDF that takes a single string and a character present
in the string as its argument, then it returns an index to the first occurrence of the character to
the string. Write a C program to read a sentence in the main program and display the string
from the index returned by the UDF using a pointer to the console.
Returns the index of the first occurrence of that character in the string.
The main program then displays the substring starting from that index using pointer
arithmetic.
Solution:
#include <stdio.h>
#include <string.h>
int index = 0;
return index;
str++;
index++;
int main() {
} else {
}
return 0;
Output:
Enter a sentence: Programming in C is powerful!
Solution:
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, M, i, sum = 0;
if (arr == NULL) {
return 1;
}
Name : Aryan Chauhan Class Roll no : 12
Section: D1 Course : BCA 2nd Sem
// Input N integers
scanf("%d", &arr[i]);
scanf("%d", &M);
if (arr == NULL) {
return 1;
scanf("%d", &arr[i]);
sum += arr[i];
free(arr);
return 0;
Output:
Enter the number of integers (N): 3
Enter 3 integers:
10 20 30
5 15
Problem Statement 20: Write a C program to dynamically allocate memory for two
user-input strings, concatenate them into a new dynamically allocated string, print the result
and free all allocated memory.
Solution:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
if (str1 == NULL) {
return 1;
free(str1);
return 1;
len1 = strlen(str1);
len2 = strlen(str2);
if (concat == NULL) {
free(str2);
return 1;
// Concatenate strings
strcpy(concat, str1);
strcat(concat, str2);
// Print result
free(str2);
free(concat);
return 0;
Output:
Enter the first string: Hello