Anand Project
Anand Project
STB-506
Semester V 2023-24
Solution 1:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float sum = 0;
sum += marks[i];
return sum / n;
float sum = 0;
return sum / n;
}
float calculateStandardDeviation(float variance) {
return sqrt(variance);
float sum = 0;
return sum / n;
// If the number of elements is even, return the average of the two middle elements
if (n % 2 == 0) {
} else {
int main() {
// Given data
int marks[] = {25, 18, 27, 8, 30, 42, 20, 50, 45, 18};
int maxCount = 1;
int currentCount = 1;
currentCount++;
} else {
maxCount = currentCount;
currentCount = 1;
}
printf("Mode: %d\n", mode);
//median
return 0;
2. WAP to find the Karl Pearson’s coefficient of correlation from the following data
between height of father (x) and son (y).
X 64 65 66 67 68 69 70
Y 66 67 65 68 70 68 72
#include <stdio.h>
#include <math.h>
return sum / n;
}
int main() {
// Given data
int x[] = {64, 65, 66, 67, 68, 69, 70};
int y[] = {66, 67, 65, 68, 70, 68, 72};
int n = sizeof(x) / sizeof(x[0]);
return 0;
}
3. WAP to find the two regression equations from the following data:
X 6 2 10 4 8
Y 9 11 5 8 7
Solution:
#include <stdio.h>
// Function to calculate mean
float calculateMean(int data[], int n) {
float sum = 0;
return sum / n;
}
return sum / n;
}
int main() {
// Given data
int x[] = {6, 2, 10, 4, 8};
int y[] = {9, 11, 5, 8, 7};
int n = sizeof(x) / sizeof(x[0]);
return 0;
}
Solution:
#include <stdio.h>
int main() {
// Given matrices A and B
int A[3][3] = {{18, 10, 9}, {12, 14, 14}, {10, 13, 10}};
int B[3][3] = {{8, 12, 16}, {10, 16, 11}, {17, 12, 15}};
// Result matrices
int resultAdd[3][3], resultSubtract[3][3], resultTransposeA[3][3], resultTransposeB[3][3],
resultMultiply[3][3];
// Perform operations
addMatrices(A, B, resultAdd);
subtractMatrices(A, B, resultSubtract);
transposeMatrix(A, resultTransposeA);
transposeMatrix(B, resultTransposeB);
multiplyMatrices(A, B, resultMultiply);
// Display results
printf("A + B:\n");
printMatrix(resultAdd);
printf("\nA - B:\n");
printMatrix(resultSubtract);
printf("\nTranspose of A:\n");
printMatrix(resultTransposeA);
printf("\nTranspose of B:\n");
printMatrix(resultTransposeB);
printf("\nA * B:\n");
printMatrix(resultMultiply);
return 0;
}
Solution:
#include <stdio.h>
int main() {
int a = 98;
int b = 56;
int result;
printf("\nChoose an operation:\n");
printf("1. a + b\n");
printf("2. a - b\n");
printf("3. a * b\n");
printf("4. a / b\n");
printf("5. a %% b\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
result = a + b;
printf("a + b = %d\n", result);
break;
case 2:
result = a - b;
printf("a - b = %d\n", result);
break;
case 3:
result = a * b;
printf("a * b = %d\n", result);
break;
case 4:
if (b != 0) {
// Avoid division by zero
result = a / b;
printf("a / b = %d\n", result);
} else {
printf("Error: Division by zero\n");
}
break;
case 5:
if (b != 0) {
// Avoid modulo by zero
result = a % b;
printf("a %% b = %d\n", result);
} else {
printf("Error: Modulo by zero\n");
}
break;
default:
printf("Invalid choice\n");
}
return 0;
}
6. Given below are the three strings:
Str1=CHANDIGARH; Str2=MADRAS; Str3=BOMBAY; Str4=AHMEDABAD
WAP (with-out using string functions) to do the following:
(a) Count the number of characters in all four strings.
(b) Count the number of vowels & consonants in strings.
(c) Concatenate the four strings into one string to be called str5.
(d) Check whether str4 is palindrome or not.
Solution:
#include <stdio.h>
#include <ctype.h>
*result = '\0';
}
int main() {
const char *Str1 = "CHANDIGARH";
const char *Str2 = "MADRAS";
const char *Str3 = "BOMBAY";
const char *Str4 = "AHMEDABAD";
char str5[100];
// Count characters
int countStr1 = countCharacters(Str1);
int countStr2 = countCharacters(Str2);
int countStr3 = countCharacters(Str3);
int countStr4 = countCharacters(Str4);
// Concatenate strings
concatenateStrings(Str1, Str2, Str3, Str4, str5);
printf("Concatenated string (str5): %s\n", str5);
return 0;
}
#include <stdio.h>
#include <string.h>
struct Census {
char city[50];
float literacyLevel;
};
scanf("%s", cities[i].city);
// Read population
printf("Population: ");
scanf("%ld", &cities[i].population);
scanf("%f", &cities[i].literacyLevel);
printf("\n");
temp = cities[j];
cities[j + 1] = temp;
}
}
temp = cities[j];
cities[j + 1] = temp;
int main() {
readCityDetails(cities, 5);
sortListByLiteracy(cities, 5);
displayList(cities, 5);
sortListByPopulation(cities, 5);
displayList(cities, 5);
return 0;