FY-Lab Exam
FY-Lab Exam
question 1
#include <stdio.h>
int main() {
// Declare variables
char str[100];
scanf("%s", str);
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) {
alphabets++;
digits++;
return 0;
}
question 2
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct Stack {
char *arr;
int top;
};
stack->top = -1;
return stack;
stack->arr[++stack->top] = element;
}
// Function to pop an element from the stack
if (!isEmpty(stack)) {
return stack->arr[stack->top--];
bool isValid(char* s) {
int length = 0;
length++;
// Initialize a stack
push(stack, s[i]);
free(stack->arr);
free(stack);
return false;
free(stack->arr);
free(stack);
return result;
int main() {
// Test cases
q3
#include <stdio.h>
#include <string.h>
int length = 0;
length++;
return length;
printf("%c", s[i]);
printf("\n");
strcpy(s1, s);
}
// Function to concatenate s and s2 and print the result
strcat(s, s2);
int main() {
scanf("%s", s);
printReverse(s);
copyAndPrint(s, s1);
scanf("%s", s2);
concatenateAndPrint(s, s2);
return 0;
q4
#include <stdio.h>
#include <string.h>
int length = 0;
length++;
s++;
return length;
printf("\n");
s++;
s1++;
int main() {
scanf("%s", s);
printReverse(s);
copyAndPrint(s, s1);
return 0;
q5
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
return false;
return true;
int main() {
char input[100];
// Test Case 1
printf("Input: MADAM\n");
printf("\n");
// Test Case 2
printf("Input: CAR\n");
q6
#include <stdio.h>
min = arr[i];
return min;
max = arr[i];
return max;
if (arr[i] == target) {
int main() {
int limit;
scanf("%d", &limit);
int arr[limit];
scanf("%d", &arr[i]);
int target;
if (result != -1) {
} else {
return 0;
q7
#include <stdio.h>
#include <string.h>
result[indices[i]] = s[i];
strcpy(s, result);
int main() {
// Test Case 1
printf("\n");
// Test Case 2
return 0;
q8
#include <stdio.h>
int main() {
int n = 5; // You can change this value to adjust the pattern size
printf("\n");
printf("\n");
return 0;
#include <stdio.h>
if (num == 0 || num == 1) {
return 1;
} else {
return num * factorial(num - 1);
int main() {
return 0;
q9
#include <stdio.h>
int main() {
int n = 5; // You can change this value to adjust the pattern size
printf("\n");
printf("\n");
printf("\n");
return 0;
#include <stdio.h>
#include <stdbool.h>
if (num <= 1) {
return false;
if (num % i == 0) {
return false;
return true;
int main() {
scanf("%d", &start);
scanf("%d", &end);
if (isPrime(i)) {
printf("%d\n", i);
return 0;
q10
#include <stdio.h>
#include <string.h>
#include <ctype.h>
if (isalpha(str[i])) {
frequency[tolower(str[i])]++;
if (frequency[i] > 0) {
int main() {
char inputString[1000];
printCharacterFrequency(inputString);
return 0;
q11
#include <stdio.h>
// Function to print Fibonacci series up to n terms
void printFibonacci(int n) {
printf("%d", first);
if (i < n - 1) {
printf(", ");
first = second;
second = next;
printf("\n");
int main() {
int terms;
scanf("%d", &terms);
printFibonacci(terms);
return 0;
q12
#include <stdio.h>
#include <ctype.h>
*vowels = *consonants = 0;
char ch = tolower(str[i]);
(*vowels)++;
} else {
(*consonants)++;
int main() {
char inputString[1000];
return 0;
q13
#include <stdio.h>
int binary[32];
int i = 0;
if (decimal == 0) {
printf("Binary: 0\n");
return;
binary[i] = decimal % 2;
decimal = decimal / 2;
i++;
}
printf("Binary: ");
printf("%d", binary[j]);
printf("\n");
int main() {
int decimal;
scanf("%d", &decimal);
decimalToBinary(decimal);
return 0;
q14
#include <stdio.h>
*start = *end;
*end = temp;
start++;
end--;
printf("\n");
int main() {
printArray(arr, size);
reverseArray(arr, size);
// Printing the reversed array
printArray(arr, size);
return 0;
q15
#include <stdio.h>
if (num % i == 0) {
sum += i;
if (i * i != num) {
sum += num / i;
if (isPerfect(i)) {
printf("\n");
int main() {
scanf("%d", &lower);
scanf("%d", &upper);
printPerfectNumbers(lower, upper);
return 0;
q16
#include <stdio.h>
#include <string.h>
struct Student {
char name[50];
char mobileNumber[15];
float marks[5];
float totalMarks;
};
printf("Name: ");
scanf("%s", students[i].name);
scanf("%s", students[i].mobileNumber);
scanf("%f", &students[i].marks[j]);
students[i].totalMarks = 0;
students[i].totalMarks += students[i].marks[j];
printf("\n");
}
}
printf("\n");
// Function to find and print details of top 5 students based on total marks
students[j + 1] = temp;
printf("Top 5 Students:\n");
int main() {
int n;
scanf("%d", &n);
readStudentDetails(students, n);
printStudentDetails(students, n);
printTopStudents(students, n);
return 0;
q18
#include <stdio.h>
// Structure to represent student details
struct Student {
int rollNo;
char name[50];
float marks[5];
float totalMarks;
char grade;
};
student->totalMarks = 0;
student->totalMarks += student->marks[i];
} else {
}
}
printf("\n");
int main() {
int n;
scanf("%d", &n);
scanf("%d", &students[i].rollNo);
printf("Name: ");
scanf("%s", students[i].name);
printf("Enter marks for 5 subjects:\n");
scanf("%f", &students[i].marks[j]);
calculateGrade(&students[i]);
printStudentDetails(&students[i]);
return 0;
q19
#include <stdio.h>
arr1[i] = arr2[i];
arr2[i] = temp;
}
printf("\n");
int main() {
int size;
scanf("%d", &size);
scanf("%d", &array1[i]);
scanf("%d", &array2[i]);
printf("Original Arrays:\n");
printf("Array 1: ");
printArray(array1, size);
printf("Array 2: ");
printArray(array2, size);
printf("Array 1: ");
printArray(array1, size);
printf("Array 2: ");
printArray(array2, size);
return 0;
q20
#include <stdio.h>
// Function to count the number of digits and calculate the sum of digits
*count = 0;
*sum = 0;
if (number < 0) {
number = -number;
while (number != 0) {
number /= 10;
(*count)++;
int main() {
scanf("%d", &num);
return 0;
}
q21
#include <stdio.h>
#include <stdlib.h>
scanf("%d", &arr[i]);
printf("Array: ");
printf("\n");
}
int main() {
int size;
scanf("%d", &size);
return 1;
readArray(array1, size);
readArray(array2, size);
printf("\nOriginal Arrays:\n");
printArray(array1, size);
printArray(array2, size);
printf("\nSum of Arrays:\n");
printArray(sumResult, size);
free(array1);
free(array2);
free(sumResult);
return 0;
q22
#include <stdio.h>
scanf("%d", &matrix[i][j]);
printf("Matrix:\n");
for (int i = 0; i < rows; i++) {
printf("\n");
printf("\n");
printf("\n");
int main() {
scanf("%d", &rows);
scanf("%d", &columns);
printf("\nOriginal Matrices:\n");
printf("\nTranspose of Matrices:\n");
return 0;
q23
#include <stdio.h>
struct Date {
int day;
int month;
int year;
};
int daysInMonth;
switch (date->month) {
daysInMonth = 31;
break;
break;
case 2:
break;
default:
printf("Invalid month\n");
return;
date->day = 1;
if (date->month == 12) {
date->month = 1;
date->year++;
} else {
date->month++;
} else {
date->day += days;
days = 0;
int main() {
addDays(¤tDate, 45);
return 0;
q24
#include <stdio.h>
struct Student {
int rollNo;
char name[50];
int age;
char address[100];
};
if (students[i].age == 14) {
printf("%s\n", students[i].name);
}
}
printf("\n");
if (students[i].rollNo % 2 == 0) {
printf("%s\n", students[i].name);
printf("\n");
int found = 0;
if (students[i].rollNo == rollNo) {
found = 1;
break;
if (!found) {
printf("\n");
int main() {
scanf("%d", &students[i].rollNo);
printf("Name: ");
scanf("%s", students[i].name);
scanf("%d", &students[i].age);
printf("Address: ");
scanf("%s", students[i].address);
printf("\n");
printNamesWithAge14(students, 5);
printNamesWithEvenRollNo(students, 5);
int searchRollNo;
scanf("%d", &searchRollNo);
displayStudentDetails(students, 5, searchRollNo);
return 0;
q25
#include <stdio.h>
struct Employee {
char name[50];
float salary;
int hoursOfWorkPerDay;
};
employee->salary += 12000;
employee->salary += 8000;
employee->salary += 4000;
int main() {
// Declare an array of structures to store employee information
printf("Name: ");
scanf("%s", employees[i].name);
printf("Salary: ");
scanf("%f", &employees[i].salary);
scanf("%d", &employees[i].hoursOfWorkPerDay);
printf("\n");
increaseSalary(&employees[i]);
// Print the names of all employees along with their final salaries
return 0;
}
q26
#include <stdio.h>
int main() {
FILE *file;
char fileName[100];
char line[100];
scanf("%s", fileName);
if (file == NULL) {
return 1;
} else {
printf("File is empty.\n");
return 0;
q27
#include <stdio.h>
#include <stdlib.h>
struct Student {
int id;
char name[50];
float marks;
};
if (student.id == searchId) {
printf("Student found!\n");
return;
int main() {
FILE *file;
if (file == NULL) {
return 1;
printf("ID: ");
scanf("%d", &students[i].id);
printf("Name: ");
scanf("%s", students[i].name);
printf("Marks: ");
scanf("%f", &students[i].marks);
int searchId;
scanf("%d", &searchId);
searchStudent(file, searchId);
fclose(file);
return 0;
q28
#include <stdio.h>
int main() {
if (sourceFile == NULL) {
return 1;
if (destinationFile == NULL) {
fclose(sourceFile);
return 1;
fputc(ch, destinationFile);
fclose(sourceFile);
fclose(destinationFile);
return 0;
}
q29
#include <stdio.h>
scanf("%d", &matrix[i][j]);
printf("Matrix:\n");
printf("%d\t", matrix[i][j]);
printf("\n");
printf("\n");
printf("\n");
int main() {
scanf("%d", &rows);
scanf("%d", &cols);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
return 0;
q30
#include <stdio.h>
scanf("%d", &matrix[i][j]);
printf("%d\t", matrix[i][j]);
printf("\n");
printf("%d\t", matrix[i][j]);
printf("\n");
int main() {
scanf("%d", &rows);
scanf("%d", &cols);
int matrix[rows][cols];
return 0;
q31
#include <stdio.h>
int main() {
FILE *file;
char fileName[50];
char ch;
int charCount = 0;
scanf("%s", fileName);
if (file == NULL) {
return 1;
charCount++;
printf("%c\n", ch);
fclose(file);
return 0;
}
q32
#include <stdio.h>
#include <string.h>
int i, j;
if (str[i] != ch) {
str[j++] = str[i];
int main() {
char inputString[100];
char characterToDelete;
inputString[len - 1] = '\0';
}
// Get character to delete from the user
deleteCharacter(inputString, characterToDelete);
return 0;
q33
#include <stdio.h>
#include <string.h>
mainStr[position + i] = subStr[i];
int main() {
char firstString[100];
char secondString[50];
int position;
scanf("%d", &position);
return 0;
}
q34
#include <stdio.h>
#include <ctype.h>
while (*str) {
*str = toupper(*str);
str++;
int main() {
char inputString[100];
inputString[len - 1] = '\0';
convertToUpperCase(inputString);
// Print the string in upper case
return 0;
#include <stdio.h>
#include <string.h>
*start = *end;
*end = temp;
start++;
end--;
int main() {
char inputString[100];
inputString[len - 1] = '\0';
reverseString(inputString);
return 0;
q35
#include <stdio.h>
while (b > 0) {
if (b % 2 == 1) {
result *= a;
}
a *= a;
b /= 2;
return result;
int main() {
scanf("%d", &base);
scanf("%d", &exponent);
return 0;
#include <stdio.h>
max = arr[i];
return max;
int main() {
int size;
scanf("%d", &size);
int array[size];
scanf("%d", &array[i]);
return 0;
}
q36
#include <stdio.h>
while (a != b) {
if (a > b) {
a -= b;
} else {
b -= a;
return a;
int main() {
scanf("%d", &num1);
scanf("%d", &num2);
return 0;
q37
#include <stdio.h>
scanf("%d", &matrix[i][j]);
}
for (int i = 0; i < rows1; i++) {
if (matrix1[i][j] != matrix2[i][j]) {
int main() {
scanf("%d", &rows1);
scanf("%d", &cols1);
scanf("%d", &rows2);
scanf("%d", &cols2);
return 0;
}
int matrix1[rows1][cols1], matrix2[rows2][cols2];
} else {
return 0;
q38
#include <stdio.h>
return;
}
// Shift elements to the right to make space for the new number
arr[position] = number;
(*size)++;
int main() {
scanf("%d", &size);
int array[size];
scanf("%d", &array[i]);
scanf("%d", &position);
printf("Enter the number to insert: ");
scanf("%d", &number);
printf("\n");
return 0;
#include <stdio.h>
return;
}
// Decrease the size of the array
(*size)--;
int main() {
scanf("%d", &size);
int array[size];
scanf("%d", &array[i]);
scanf("%d", &position);
}
printf("\n");
return 0;
q39
#include <stdio.h>
arr1[i] = arr2[i];
arr2[i] = temp;
if (size1 != size2) {
if (arr1[i] != arr2[i]) {
}
return 1; // Arrays are equal
int main() {
scanf("%d", &size1);
int array1[size1];
scanf("%d", &array1[i]);
scanf("%d", &size2);
int array2[size2];
scanf("%d", &array2[i]);
printf("\nAfter Swapping:\n");
printf("\n");
printf("\n");
} else {
return 0;
q40
#include <stdio.h>
#include <string.h>
// Function to swap two strings
char temp[100]; // Assuming a maximum length of 100 characters for each string
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
int main() {
string1[len1 - 1] = '\0';
string2[len2 - 1] = '\0';
swapStrings(string1, string2);
printf("\nAfter Swapping:\n");
return 0;
q41
#include <stdio.h>
int i, j, temp;
temp = arr[j];
int main() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
bubbleSort(arr, n);
printf("\nSorted Array:\n");
printf("\n");
return 0;
q42
#include <stdio.h>
minIndex = i;
minIndex = j;
temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
int main() {
int n;
// Get the number of elements from the user
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
selectionSort(arr, n);
printf("\nSorted Array:\n");
printf("\n");
return 0;
q43
#include <stdio.h>
if (arr[i] == key) {
max = arr[i];
return max;
int main() {
int n, key;
scanf("%d", &n);
int arr[n];
// Get elements from the user
scanf("%d", &arr[i]);
scanf("%d", &key);
if (index != -1) {
} else {
return 0;
q44
#include <stdio.h>
// Function to find duplicate elements in an array
if (arr[i] == arr[j]) {
int main() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
printf("\nDuplicate Elements:\n");
findDuplicates(arr, n);
return 0;
q45
#include <stdio.h>
return;
// Shift elements to the right to make space for the new element
arr[position] = element;
(*size)++;
int main() {
scanf("%d", &size);
int arr[size];
scanf("%d", &arr[i]);
scanf("%d", &position);
scanf("%d", &element);
printf("\n");
return 0;