Exam
Exam
struct weight {
int grams;
int kilograms;
};
#include <stdio.h>
struct weight {
int grams;
int kilograms;
};
return result;
}
int main() {
// Define two weights
struct weight weight1 = {100, 10}; // 10 kg 100 g
struct weight weight2 = {1800, 5}; // 5 kg 1800 g
return 0;
}
Task 2
Using #define preprocessor write Macros and use it
circle_length
#include <stdio.h>
#include <math.h>
int main() {
return 0;
Task 3
Students {
char [10] first_name;
char [15] last_name;
int age;
int midtermExamGrade;
int finalExamGrade
}
And sort it according age in descending order. Then output data.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
// Dynamically allocate memory for an array of 5 Students
struct Student *students = (struct Student*)malloc(5 * sizeof(struct
Student));
return 0;
}
Task 4
The algorithm for calculating the value of the function F (n), where n is a
natural number, is:
F(n<=1) = 1
F(n) = F(n–1) * (n + 4), n > 1
recursive
#include <stdio.h>
int recursiveF(int n) {
if (n <= 1) {
return 1;
} else {
return recursiveF(n - 1) * (n + 4);
}
}
int main() {
int n = 5; // You can change the value of n as needed
int result = recursiveF(n);
return 0;
}
inerative
#include <stdio.h>
int iterativeF(int n) {
int result = 1;
while (n > 1) {
result *= (n + 4);
n--;
}
return result;
}
int main() {
int n = 5; // You can change the value of n as needed
int result = iterativeF(n);
return 0;
}
Task 5
You have 2D array [5][4]. Please write program for finding column’s number
with minimal sum of elements
#include <stdio.h>
int main() {
// Define a 2D array [5][4]
int array[5][4] = {
{3, 7, 1, 5},
{2, 8, 4, 6},
{9, 2, 8, 3},
{5, 1, 7, 4},
{6, 3, 2, 9}
};
// Calculate the sum of each column and find the column with the minimal
sum
for (int j = 0; j < 4; ++j) {
int columnSum = 0;
for (int i = 0; i < 5; ++i) {
columnSum += array[i][j];
}
return 0;
}
Task 6
User enters the x and n= 1..3, which is number of action
Using switch construction, calculate and output the answer
1) -2x2-4; 2) 5x+2; 3) 15-3x.
#include <stdio.h>
int main() {
// Input values from the user
double x;
int n;
return 0;
}
Task 7
Find the maximum element with an even index in the array.
#include <stdio.h>
int main() {
// Define an array
int array[] = {10, 5, 20, 8, 15, 7, 25, 12};
Task 8
Create Function using reference and use it inside of main
void circle_length (int *a)
#include <stdio.h>
#include <math.h>
int main() {
// Initialize the radius
int radius = 5;
return 0;
}
Task 9
Write a program to write an 1D array to a file
#include <stdio.h>
int main() {
// Define an array
int array[] = {10, 20, 30, 40, 50};
return 0;
}