Skip to content

Commit c4ffa22

Browse files
Learned new topic
1 parent b197522 commit c4ffa22

File tree

5 files changed

+218
-0
lines changed

5 files changed

+218
-0
lines changed

Structure/Practice/Qs_56.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Enter address (house no, block, city, state) of 5 people
2+
#include <stdio.h>
3+
typedef struct people_details
4+
{
5+
char name[20];
6+
char house_no[20];
7+
char block[40];
8+
char city[20];
9+
char state[20];
10+
int postal_code;
11+
} log;// alias of sturct people_details
12+
13+
void initialscanInfo (int *n)
14+
{
15+
printf("How many people's address do you want to save : ");
16+
scanf("%d", &(*n));
17+
getchar();// for consuming newline character from the buffer
18+
}
19+
20+
void scanInfo (log *people, int n)
21+
{
22+
for (int i = 0; i < n; i++)
23+
{
24+
printf("Stranger's Information: %d\n\n", i+1);
25+
printf("Name: ");
26+
fgets(people[i].name, sizeof(people->name), stdin);
27+
printf("House no: ");
28+
fgets(people[i].house_no, sizeof(people->house_no), stdin);
29+
printf("Block: ");
30+
fgets(people[i].block, sizeof(people->block), stdin);
31+
printf("City: ");
32+
fgets(people[i].city, sizeof(people->city), stdin);
33+
printf("State: ");
34+
fgets(people[i].state, sizeof(people->state), stdin);
35+
printf("Postal code: ");
36+
scanf("%d", &people[i].postal_code);
37+
getchar();// Consumes newline character after the integer input
38+
}
39+
40+
}
41+
42+
void printInfo (log people[], int n)
43+
{
44+
for (int i = 0; i < n; i++)
45+
{
46+
printf("Stranger's Information: %d\n\n", i+1);
47+
printf("Stranger's name: %s", people[i].name);
48+
printf("Stranger's house no : %s", people[i].house_no);
49+
printf("Stranger's block: %s", people[i].block);
50+
printf("Stranger's city: %s", people[i].city);
51+
printf("Stranger's state: %s", people[i].state);
52+
printf("Stranger's postal code: %d\n\n", people[i].postal_code);
53+
}
54+
55+
}
56+
57+
int main ()
58+
{
59+
int n;//number of person
60+
initialscanInfo(&n);
61+
62+
log person[n];
63+
64+
scanInfo(person, n);//takes input
65+
printInfo(person, n);//prints address
66+
67+
return 0;
68+
}

Structure/Practice/Qs_57.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Create a structure to store vectors. then make a fucntion to return sum of 2 vectors
2+
// important
3+
#include <stdio.h>
4+
typedef struct vectors
5+
{
6+
float x;
7+
float y;
8+
float sum;
9+
} vec;
10+
11+
void scanInfo (vec *vector, vec *vector2)
12+
{
13+
scanf("%f%f", &vector->x, &vector->y);
14+
scanf("%f%f", &vector2->x, &vector2->y);
15+
}
16+
17+
void vector_summation (vec vector1, vec vector2, vec sum)
18+
{
19+
sum.x = vector1.x+vector2.x;
20+
sum.y = vector1.y+vector2.y;
21+
printf("Sum of x = %0.2f\nSum of y = %0.2f\n", sum.x, sum.y);
22+
}
23+
24+
int main ()
25+
{
26+
vec vector1, vector2;
27+
vec sum = {0};
28+
29+
scanInfo(&vector1, &vector2);
30+
vector_summation(vector1, vector2, sum);
31+
32+
return 0;
33+
}
34+
35+
/*
36+
vector 1 = Xi + Yj
37+
vector 2 = X'i + Y'j
38+
sum of vector 1 and 2 = (X+X')i + (Y+Y')j (sum of both axis in icap and jcap)
39+
*/

Structure/Practice/Qs_58.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Create a structure to store complex number (use arrow operator)
2+
#include <stdio.h>
3+
typedef struct complex
4+
{
5+
int real;
6+
char operator;
7+
int imaginary;
8+
} com;
9+
10+
void scanInfo (com *number)
11+
{
12+
printf("Real Number: ");
13+
scanf("%d", &number->real);
14+
getchar();// cosumes newline character from buffer
15+
printf("Operator: ");
16+
scanf("%c", &number->operator);
17+
printf("Imaginary Number: ");
18+
scanf("%d", &number->imaginary);
19+
}
20+
21+
void printInfo (com number)
22+
{
23+
printf("Complex number: %d%c%di\n", number.real, number.operator, number.imaginary);
24+
}
25+
26+
int main ()
27+
{
28+
com number1;
29+
scanInfo(&number1);
30+
31+
printInfo(number1);
32+
33+
return 0;
34+
}

Structure/Practice/Qs_59.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Theoretical Question
2+
3+
You have to store the marks of 30 students in class
4+
What will you use?
5+
6+
a. array of 30 floats
7+
b. sturcture
8+
9+
ans: a bcause we just have to store marks of 30 students so it better
10+
to choose array of 30 floats, but we can use both, we use structure to
11+
store different types of data, but here we are storing only one type.
12+
*/
13+
// array of 30 floats
14+
#include <stdio.h>
15+
int main ()
16+
{
17+
float numbers[30] = {12.2, 21.3, 49.3, 19.9, 34, 34, 12, 23, 34, 43.3,
18+
13.1, 29.5, 30, 12.3, 38, 10.4, 43.1, 12, 21, 12,
19+
45, 2, 0, 12, 43, 19.4, 12, 23, 12, 21};
20+
for (int i = 0; i < 30; i++)
21+
{
22+
printf("%dth student's mark: %0.1f\n", i+1, numbers[i]);
23+
}
24+
25+
return 0;
26+
}

Structure/Practice/Qs_60.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Make a structure to store Bank Account Information of a customer of ABC Bank. Also, make an alias for it.
2+
#include <stdio.h>
3+
typedef struct account
4+
{
5+
char account_number[20];
6+
char account_type[10];
7+
char key[10];
8+
char name[20];
9+
char blood[10];
10+
char nid[20];
11+
char phone[20];
12+
char address[50];
13+
char profession[20];
14+
char nominee_name[20];
15+
char nominee_blood[10];
16+
char nominee_nid[20];
17+
char nominee_phone[20];
18+
char nominee_profession[10];
19+
char nominee_relation[10];
20+
int credit_history;
21+
} data;
22+
23+
void printInfo (data customer)
24+
{
25+
printf("Customer details :\n\n");
26+
printf("Account no : %s\n", customer.account_number);
27+
printf("Account type : %s\n", customer.account_type);
28+
printf("Account key : %s\n", customer.key);
29+
printf("Account holder name : %s\n", customer.name);
30+
printf("Account holder blood group : %s\n", customer.blood);
31+
printf("Account holder nid no : %s\n", customer.nid);
32+
printf("Account holder phone no : %s\n", customer.phone);
33+
printf("Account holder address : %s\n", customer.address);
34+
printf("Account holder profession : %s\n", customer.profession);
35+
printf("Account nominee name : %s\n", customer.nominee_name);
36+
printf("Account nominee blood group : %s\n", customer.nominee_blood);
37+
printf("Account nominee nid no : %s\n", customer.nominee_nid);
38+
printf("Account nominee phone no : %s\n", customer.nominee_phone);
39+
printf("Account nominee profession : %s\n", customer.nominee_profession);
40+
printf("Account nominee relation : %s\n", customer.nominee_relation);
41+
printf("Account holder credit history : %d credit\n", customer.credit_history);
42+
}
43+
44+
int main ()
45+
{
46+
data customer1 = {"ABC12094354", "Regular", "ky2#1@8*z", "Nazmus Sakib", "A+", "45123413121", "(+880)1881296235", "65/5 Kadamtala, East Basabo, Dhaka-1214", "Software Engineer",
47+
"Umme Kulsum", "AB+", "49213845320", "+8801907232841", "Housewife", "Mother", 180 };
48+
printInfo(customer1);
49+
50+
return 0;
51+
}

0 commit comments

Comments
 (0)