Skip to content

Commit

Permalink
Merge branch 'SharafatKarim:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sadman2084 authored Aug 11, 2023
2 parents 66ef855 + f82107c commit 5f487c7
Show file tree
Hide file tree
Showing 31 changed files with 1,435 additions and 154 deletions.
330 changes: 197 additions & 133 deletions README.md

Large diffs are not rendered by default.

62 changes: 42 additions & 20 deletions questions/11.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
1. Define a structure data type called time_struct
containing three members integer hour, integer
minute and integer second . Develop a program
1. Define a structure data type called *time_struct*
containing three members integer *hour*, integer
*minute* and integer *second* . Develop a program
that would assign values to the individual members
and display the time in the following form:
```
16:40:51
```

2. Modify the above program such that a function is
used to input values to the members and another
function to display the time.

3. Design a function update that would accept the
3. Design a function *update* that would accept the
data structure designed in Exercise 11.1 and
increments time by one second and returns the new
time. (If the increment results in 60 seconds, then
Expand All @@ -19,42 +21,49 @@ member is incremented by one. Then, if the result is
the hour member is incremented by one. Finally
when the hour becomes 24, it is set to zero.)

4. Define a structure data type named date containing three
integer members day , month , and year. Develop an interactive
4. Define a structure data type named *date* containing three
integer members *day* , *month* , and *year*. Develop an interactive
modular program to perform the following tasks:
```
(a) To read data into structure mem bers by a function
(b) To validate the date entered by another function
(c) To print the date in the format
April 29, 2002
by a third function.
```
The input data should be three integers like 29, 4,
and 2002 corresponding to day, month, and year.
Examples of invalid data:
```
31, 4, 2002 – April has only 30 days
29, 2, 2002 – 2002 is not a leap year
```

5. Design a function update that accepts the date
5. Design a function *update* that accepts the *date*
structure designed in Exercise 11.4 to increment the
date by one day and return the new date. The
following rules are applicable:
```
(a) If the date is the last day in a month, month should
be incremented
(b) If it is the last day in December, the year should
be incremented
(c) There are 29 days in February of a leap year
```

6. Modify the input function used in Exercise 11.4 such
that it reads a value that represents the date in the
form of a long integer, like 19450815 for the date
15-8-1945 (August 15, 1945) and assigns suitable
values to the members day, month , and year.
Use suitable algorithm to
> Use suitable algorithm to
convert the long integer 19450815 into year, month
and day.

7. Add a function called nextdate to the program
designed in Exercise 11.4 to perform the following
task:
```
(a) Accepts two arguments, one of the structure data
containing the present date and the second an
integer that represents the number of days to be
Expand All @@ -63,74 +72,87 @@ added to the present date.
structure containing the next date correctly.
Note that the next date may be in the next month or
even the next year.
```

8. Use the date structure defined in Exercise 11.4 to
8. Use the *date* structure defined in Exercise 11.4 to
store two dates. Develop a function that will take
these two dates as input and compares them.
(a) It returns 1, if the date1 is earlier than date2
(b) It returns 0, if date1 is later date
```
(a) It returns 1, if the *date1* is earlier than *date2*
(b) It returns 0, if *date1* is later date
```

9. Define a structure to represent a vector (a series of
integer values) and write a modular program to
perform the following tasks:
```
(a) To create a vector
(b) To modify the value of a given element
(c) To multiply by a scalar value
(d) To display the vector in the form
(10, 20, 30, . . . . . ..)
```

10. Add a function to the program of Exercise 11.9 that
accepts two vectors as input parameters and return
the addition of two vectors.

11. Create two structures named metric and British which store
the values of distances. The metric structure stores
11. Create two structures named *metric* and *British* which store
the values of distances. The *metric* structure stores
the values in metres and centimetres and the British
structure stores the values in feet and inches. Write
a program that reads values for the structure
variables and adds values contained in one variable
of metric to the contents of another variable of
British. The program should display the result in the
of *metric* to the contents of another variable of
*British*. The program should display the result in the
format of feet and inches or metres and centimetres
as required.

12. Define a structure named census with the
12. Define a structure named *census* with the
following three members:
```
(a) A character array city [ ] to store names
(b) A long integer to store population of the city
(c) A float member to store the literacy level
```
Write a program to do the following:
```
(a) To read details for 5 cities randomly using an
array variable
(b) To sort the list alphabetically
(c) To sort the list based on literacy level
(d) To sort the list based on population
(e) To display sorted lists
```

13. Define a structure that can describe an hotel. It
should have members that include the name,
address, grade, average room charge, and number
of rooms.
Write functions to perform the following operations:
```
(a) To print out hotels of a given grade in order of
charges.
(b) To print out hotels with room charges less than a
given value.
```

14. Define a structure called cricket that will describe
14. Define a structure called *cricket* that will describe
the following information:
```
player name
team name
batting average
Using cricket, declare an array player with 50
```
Using *cricket*, declare an array *player* with 50
elements and write a program to read the
information about all the 50 players and print a
team-wise list containing names of players with their
batting average.

15. Design a structure student_record to contain
15. Design a structure *student_record* to contain
name, date of birth, and total marks obtained. Use
the date structure designed in Exercise 11.4 to
the *date* structure designed in Exercise 11.4 to
represent the date of birth.
Develop a program to read data for 10 students in a
class and list them rank-wise.
Expand Down
2 changes: 1 addition & 1 deletion solutions/sadman/10/4.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

Expand Down
18 changes: 18 additions & 0 deletions solutions/sharafat/10/1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>

int a = 10, b = 20;

void swap (void)
{
b = a + b ;
a = b - a ;
b = b - a ;
}

int main()
{
printf("Before swap: a = %d, b = %d\n", a, b);
swap();
printf("After swap: a = %d, b = %d\n", a, b);
return 0;
}
44 changes: 44 additions & 0 deletions solutions/sharafat/10/10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <math.h>

float perimeter(float a, float b, float c)
{
return a + b + c;
}

float area(float a, float b, float c)
{
float s = (a + b + c) / 2;
return sqrt((s - a) * (s - b) * (s - c));
}

int main()
{
float a, b, c;
char operation;

printf("Enter first side: ");
scanf("%f", &a);
printf("Enter second side: ");
scanf("%f", &b);
printf("Enter third side: ");
scanf("%f", &c);

printf("Enter one of the followings: ");
printf("\n(a) Perimeter of the triangle ");
printf("\n(b) Area of the triangle ");
printf("\n");

scanf(" %c", &operation);
switch (operation)
{
case 'a':
printf("Result -> %f\n", perimeter(a, b, c));
break;
case 'b':
printf("Result -> %f\n", area(a, b, c));
break;
default:
printf("Invalid operation\n");
}
}
32 changes: 32 additions & 0 deletions solutions/sharafat/10/11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>

int find_largest(int *matrix, int rows, int cols) {
int i, j, largest = *matrix;
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
if (*(matrix + i * cols + j) > largest) {
largest = *(matrix + i * cols + j);
}
}
}
return largest;
}

int main() {
int m, n, i, j;
printf("Enter number of rows and columns: ");
scanf("%d %d", &m, &n);

int matrix[m][n];
printf("Enter matrix elements: \n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &matrix[i][j]);
}
}

int largest = find_largest(&matrix[0][0], m, n);
printf("Largest element in the matrix is %d\n", largest);

return 0;
}
64 changes: 64 additions & 0 deletions solutions/sharafat/10/12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdio.h>

void multiply_matrices(int *matrix_one, int *matrix_two, int m, int n)
{
int i, j, k;
int result[m][m];

for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
{

result[i][j] = 0;
for (k = 0; k < n; k++)
{
result[i][j] += *(matrix_one + i * n + k) * *(matrix_two + k * m + j);
}
}
}

printf("Resultant matrix: \n");
for (i = 0; i < m; i++)
{
printf("[");
for (j = 0; j < m; j++)
{
printf(" %d ", result[i][j]);
}
printf("]\n");
}
}

int main()
{
int m, n;
printf("Enter m and n (mxn) (nxm): ");
scanf("%d %d", &m, &n);

int matrix_one[m][n];
int matrix_two[n][m];
int i, j;

printf("Enter matrix one elements: \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Enter element at (%d, %d): ", i, j);
scanf("%d", &matrix_one[i][j]);
}
}

printf("Enter matrix two elements: \n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
printf("Enter element at (%d, %d): ", i, j);
scanf("%d", &matrix_two[i][j]);
}
}

multiply_matrices((int *)matrix_one, (int *)matrix_two, m, n);
}
Loading

0 comments on commit 5f487c7

Please sign in to comment.