Answer To The Question No 1
Answer To The Question No 1
Id . 0112330821
Section .E
Cse 1111
a. #include <stdio.h>
int factorial(int n)
{ int result = 1; for (int i = 1; i <= n; i++)
{ result *= i; } return result; }
int sum(int a, int b)
{ return a + b; }
int main()
{ int num1, num2, num3;
printf("Enter three integers: ");
scanf("%d %d %d", &num1, &num2, &num3);
int factorialSum = sum(factorial(num1), sum(factorial(num2), factorial(num3)));
printf("Sum of factorials: %d\n", factorialSum);
return o;
}
I a B
0 10 30
1 30 19
2 49 18
b#include <stdio.h>
int main() {
char str[55] = "I love spl. Uiu has some good labs for spl.";
char newStr[55];
int i, j, k;
i = 0;
j = 0;
while (str[i] != '\0') {
if (str[i] == 's' && str[i+1] == 'p' && str[i+2] == 'l') {
for (k = 0; k < 3; k++) {
i++;
}
newStr[j++] = 'd';
newStr[j++] = 's';
newStr[j++] = 'a';
} else {
newStr[j++] = str[i++];
}
}
newStr[j] = '\0';
printf("%s\n", newStr);
return 0;
}
a.
#include <stdio.h>
#include <string.h> // For safer string manipulation
struct student {
char name[50]; // Allocate enough space for common names and a null terminator
int ID;
};
int main() {
struct student s1, s2;
printf("\nStudent Details:\n");
printf("Student 1:\n");
printf(" Name: %s\n", s1.name);
printf(" ID: %d\n", s1.ID);
printf("Student 2:\n");
printf(" Name: %s\n", s_ptr->name);
printf(" ID: %d\n", s_ptr->ID);
return 0;
}
b. #include <stdio.h>
#include <string.h>
int main() {
struct Patient patients[100];
int n, i, youngestPatientIndex;
float lowestBMI = 9999.0; // Initialize with a high value
// Calculate BMI
patients[i].BMI = patients[i].weight / (patients[i].height * patients[i].height);
}
return 0;
}
a.
Inside power_of_2(16)
Inside power_of_2(8)
Inside power_of_2(4)
Inside power_of_2(2)
Inside power_of_2(1)
b. 1 2 4 5 6 7 8 9
a. #include <stdio.h>
int main() {
int arr[100];
int i, largest;
largest = *arrPtr;
return 0;
b#include <stdio.h>
int main() {
if (fp == NULL) {
return 1;
}
fclose(fp);
return 0;