Professional Documents
Culture Documents
Lab Session 3 P2
Lab Session 3 P2
P2
P2
P3
LAB SESSION 4
1
LAB SESSION 5
LAB SESSION 6
1)Write a C Program to sort an array of integers using pointer.
CODE
#include <stdio.h>
temp = *i;
*i = *j;
*j = temp;
int main() {
printf("\n");
sortArray(arr, size);
printf("\n");
return 0;
}
*x = *y;
*y = temp;
int length = 0;
length++;
str++;
return length;
if (start == end) {
printf("%s\n", str);
} else {
int main() {
char str[100];
scanf("%s", str);
int n = stringLength(str);
generatePermutations(str, 0, n - 1);
return 0;
*x = *y;
*y = temp;
int length = 0;
length++;
str++;
return length;
if (start == end) {
printf("%s\n", str);
} else {
int main() {
char str[100];
scanf("%s", str);
int n = stringLength(str);
generatePermutations(str, 0, n - 1);
return 0;
#include <ctype.h>
int i = 0, j = 0;
if (isalpha(str[i])) {
str[j++] = str[i];
i++;
str[j] = '\0';
int main() {
char str[100];
removeNonAlphabetic(str);
return 0;
Lab session 8
Code
#include <stdio.h>
*x = *y;
*y = temp;
printf("\n");
int main() {
printArray(arr, size);
sortAscending(arr, size);
printArray(arr, size);
sortDescending(arr, size);
printArray(arr, size);
return 0;
}
#include <stdio.h>
int i, j, k;
} else {
j++;
}
return size; // Return the new size of the array
printf("\n");
int main() {
printArray(arr, size);
printArray(arr, size);
return 0;
}
#include <stdio.h>
void separateOddEven(int *arr, int size, int *oddArr, int *evenArr, int *oddSize, int *evenSize) {
if (*(arr + i) % 2 == 0) {
(*evenSize)++;
} else {
(*oddSize)++;
printf("\n");
int main() {
printArray(arr, size);
printArray(oddArr, oddSize);
printArray(evenArr, evenSize);
return 0;
}
#include <stdio.h>
double fahrenheitToCelsius(double x) {
double sphereVolume(double x) {
double linearFunction(double x) {
if (x >= 0 && x <= 60) {
return x * 60;
} else {
int main() {
double x;
scanf("%lf", &x);
if (result != -1) {
} else {
return 0;
Lab session 9
#include <stdio.h>
#include <stdlib.h>
return largest;
int main() {
int *arr;
int size;
if (arr == NULL) {
free(arr);
return 0;
}
Code
#include <stdio.h>
#include <stdbool.h>
}
int main() {
char str[100];
scanf("%s", str);
int length = 0;
length++;
} else {
return 0;
}
#include <stdio.h>
#include <stdbool.h>
// Function to print the largest and smallest words from a given sentence
int i = 0, j = 0;
while (true) {
int wordLength = j;
strcpy(largestWord, currentWord);
smallestLength = wordLength;
strcpy(smallestWord, currentWord);
j = 0;
break;
} else {
currentWord[j++] = sentence[i];
i++;
int main() {
char sentence[1000];
printLargestAndSmallestWord(sentence);
return 0;
#include <stdio.h>
#include <stdlib.h>
int main() {
int size;
scanf("%d", &size);
// Dynamically allocate memory for arrays A, B, and C
return 1;
scanf("%d", &A[i]);
scanf("%d", &B[i]);
printf("Result is:\n");
printf("%d\n", C[i]);
free(A);
free(B);
free(C);
return 0;
Lab seeion 10
Code
#include <stdio.h>
struct Student {
char name[50];
int age;
float totalMarks;
};
int main() {
scanf("%s", student1.name);
scanf("%d", &student1.age);
scanf("%f", &student1.totalMarks);
scanf("%s", student2.name);
scanf("%d", &student2.age);
scanf("%f", &student2.totalMarks);
printf("Grades:\n");
printf("Grade: A\n");
printf("Grade: B\n");
printf("Grade: C\n");
printf("Grade: D\n");
} else {
printf("Grade: F\n");
return 0;
Code
#include <stdio.h>
struct Date {
int day;
int month;
int year;
};
} else {
int days[] = {31, 28 + isLeapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int days1 = d1.year * 365 + d1.day; // Convert year and day of d1 into days
days1 += (d1.year / 4 - d1.year / 100 + d1.year / 400); // Adjust for leap years
int days2 = d2.year * 365 + d2.day; // Convert year and day of d2 into days
days2 += (d2.year / 4 - d2.year / 100 + d2.year / 400); // Adjust for leap years
int main() {
// Input date 1
// Input date 2
return 0;
}
#include <stdio.h>
struct Complex {
float real;
float imag;
};
return result;
return result;
}
int main() {
return 0;
}
#include <stdio.h>
#include <string.h>
struct Book {
int accessionNumber;
char author[50];
char title[100];
};
// Function prototypes
int main() {
int numBooks = 0;
int choice;
do {
// Display menu
printf("\nLibrary Menu\n");
printf("0 - Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
if (numBooks > 0) {
displayAllBooks(library, numBooks);
} else {
break;
case 2:
addNewBook(library, &numBooks);
break;
case 3:
displayBooksByAuthor(library, numBooks);
break;
case 4:
displayNumBooksByTitle(library, numBooks);
break;
case 5:
displayTotalNumBooks(library, numBooks);
break;
case 6:
issueBook(library, numBooks);
break;
case 0:
break;
default:
return 0;
printf("Library Books:\n");
displayBookInfo(books[i]);
scanf("%d", &newBook.accessionNumber);
printf("Author: ");
scanf("%s", newBook.author);
printf("Title: ");
scanf("%s", newBook.title);
books[*numBooks] = newBook;
(*numBooks)++;
} else {
}
// Function to display all books by a particular author
char author[50];
int found = 0;
scanf("%s", author);
if (strcmp(books[i].author, author) == 0) {
displayBookInfo(books[i]);
found = 1;
if (!found) {
char title[100];
int count = 0;
scanf("%s", title);
if (strcmp(books[i].title, title) == 0) {
count++;
int accessionNumber;
scanf("%d", &accessionNumber);
int found = 0;
if (books[i].accessionNumber == accessionNumber) {
if (books[i].isIssued) {
} else {
found = 1;
break;
if (!found) {
}
Code
#include <stdio.h>
#include <string.h>
#define MAX_CUSTOMERS 10
struct Customer {
char name[50];
int accountNumber;
float balance;
};
printf("%s\n", customers[i].name);
}
// Function to add $100 to the balance of customers with balance more than $1000
customers[i].balance += 100.0;
int main() {
};
printCustomersWithLowBalance(customers, numCustomers);
// Add $100 to balance of customers with balance more than $1000 and print incremented
balances
addBalanceForRichCustomers(customers, numCustomers);
return 0;
PATTERN
Write a C Program to print pascal's triangle.
#include <stdio.h>
int main() {
int rows, coef = 1;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
int main() {
int rows, num = 1;
return 0;
}