Skip to content

Commit fb9928e

Browse files
authored
cwh
1 parent 72efa87 commit fb9928e

11 files changed

+310
-0
lines changed

09_01_structures.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
struct employee{
5+
int code;
6+
float salary;
7+
char name[10];
8+
};
9+
10+
int main(){
11+
int a =34;
12+
char b = 'g';
13+
float d = 234.3543;
14+
// employee e1;
15+
// e1.salary = 34.454; --->wont work without employee structure
16+
17+
struct employee e1;
18+
e1.code = 100;
19+
e1.salary = 34.454;
20+
// e1.name = "Harry"; --> wont work
21+
strcpy(e1.name, "Harry");
22+
23+
printf("%d\n", e1.code);
24+
printf("%.3f\n", e1.salary);
25+
printf("%s\n", e1.name);
26+
27+
return 0;
28+
}

09_02_strucuture_input.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
struct employee{
5+
int code;
6+
float salary;
7+
char name[10];
8+
};
9+
10+
int main(){
11+
struct employee e1, e2, e3;
12+
printf("Enter the value for code of e1: ");
13+
scanf("%d", &e1.code);
14+
printf("Enter the value for salary of e1: ");
15+
scanf("%f", &e1.salary);
16+
printf("Enter the value for name of e1: ");
17+
scanf("%s", e1.name);
18+
19+
printf("Enter the value for code of e2: ");
20+
scanf("%d", &e2.code);
21+
printf("Enter the value for salary of e2: ");
22+
scanf("%f", &e2.salary);
23+
printf("Enter the value for name of e2: ");
24+
scanf("%s", e2.name);
25+
26+
printf("Enter the value for code of e3: ");
27+
scanf("%d", &e3.code);
28+
printf("Enter the value for salary of e3: ");
29+
scanf("%f", &e3.salary);
30+
printf("Enter the value for name of e3: ");
31+
scanf("%s", e3.name);
32+
33+
return 0;
34+
}

09_03_array_of_structures.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
struct employee{
5+
int code;
6+
float salary;
7+
char name[20];
8+
};
9+
10+
int main(){
11+
struct employee facebook[100];
12+
13+
facebook[0].code = 100;
14+
facebook[0].salary = 100.45;
15+
strcpy(facebook[0].name, "Harry");
16+
17+
facebook[1].code = 101;
18+
facebook[1].salary = 90.45;
19+
strcpy(facebook[1].name, "Rohan");
20+
21+
facebook[2].code = 102;
22+
facebook[2].salary = 110.45;
23+
strcpy(facebook[2].name, "SkillKhiladi");
24+
printf("Done");
25+
26+
return 0;
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
struct employee{
5+
int code;
6+
float salary;
7+
char name[20];
8+
};
9+
10+
int main(){
11+
struct employee harry = {100, 34.23, "Harry"};
12+
13+
printf("Code is: %d \n", harry.code);
14+
printf("Salary is: %f \n", harry.salary);
15+
printf("Name is: %s \n", harry.name);
16+
17+
18+
return 0;
19+
}

09_05_pointer_to_structures.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
struct employee{
5+
int code;
6+
float salary;
7+
char name[20];
8+
};
9+
10+
int main(){
11+
struct employee e1;
12+
struct employee *ptr;
13+
14+
ptr = &e1;
15+
//(*ptr).code = 101; //or you can also write: ptr->code = 101;
16+
ptr->code = 101;
17+
printf("%d", e1.code);
18+
19+
return 0;
20+
}

09_06_show_function.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
struct employee{
5+
int code;
6+
float salary;
7+
char name[20];
8+
};
9+
10+
void show(struct employee emp){
11+
printf("The Code of employee is: %d\n", emp.code);
12+
printf("The Salary of employee is: %f\n", emp.salary);
13+
printf("The Name of employee is: %s\n", emp.name);
14+
emp.code = 34;
15+
}
16+
int main(){
17+
struct employee e1;
18+
struct employee *ptr;
19+
20+
ptr = &e1;
21+
//(*ptr).code = 101; //or you can also write: ptr->code = 101;
22+
ptr->code = 101;
23+
ptr->salary = 11.01;
24+
strcpy(ptr->name, "Harry");
25+
26+
show(e1);
27+
printf("The Code of employee is: %d\n", e1.code);
28+
29+
return 0;
30+
}

09_07_typedef.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
typedef struct employee{
5+
int code;
6+
float salary;
7+
char name[20];
8+
} emp;
9+
10+
void show(emp emp1){
11+
printf("The Code of employee is: %d\n", emp1.code);
12+
printf("The Salary of employee is: %f\n", emp1.salary);
13+
printf("The Name of employee is: %s\n", emp1.name);
14+
15+
}
16+
17+
int main(){
18+
// Declaring e1 and ptr
19+
emp e1;
20+
emp *ptr;
21+
22+
// pointing ptr to e1
23+
ptr = &e1;
24+
25+
// Set the member values for e1
26+
ptr->code = 101;
27+
ptr->salary = 11.01;
28+
strcpy(ptr->name, "Harry");
29+
30+
show(e1);
31+
32+
return 0;
33+
}

09_08_pr_01.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include<stdio.h>
2+
3+
struct vector{
4+
int x;
5+
int y;
6+
};
7+
8+
int main(){
9+
struct vector v1, v2;
10+
v1.x = 34;
11+
v1.y = 54;
12+
printf("X dim is %d and Y dim is %d\n", v1.x, v1.y);
13+
14+
v2.x = 3345;
15+
v2.y = 534;
16+
printf("X dim is %d and Y dim is %d\n", v2.x, v2.y);
17+
return 0;
18+
}

09_09_pr_02.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<stdio.h>
2+
3+
struct vector{
4+
int x;
5+
int y;
6+
};
7+
8+
struct vector sumVector(struct vector v1, struct vector v2){
9+
struct vector result;
10+
result.x = v1.x + v2.x;
11+
result.y = v1.y + v2.y;
12+
return result;
13+
}
14+
int main(){
15+
struct vector v1, v2, sum;
16+
v1.x = 4;
17+
v1.y = 9;
18+
printf("X dim is %d and Y dim is %d\n", v1.x, v1.y);
19+
20+
v2.x = 5;
21+
v2.y = 4;
22+
printf("X dim is %d and Y dim is %d\n", v2.x, v2.y);
23+
24+
sum = sumVector(v1, v2);
25+
printf("X dim of result is %d and Y dim is %d\n", sum.x, sum.y);
26+
return 0;
27+
}

09_10_pr_06.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<stdio.h>
2+
3+
typedef struct complex{
4+
int real;
5+
int complex;
6+
}comp;
7+
8+
void display(comp c){
9+
printf("The value of real part is %d\n", c.real);
10+
printf("The value of Imaginary part is %d\n", c.complex);
11+
}
12+
13+
int main(){
14+
comp cnums[5];
15+
for(int i=0; i<5; i++){
16+
printf("Enter the real value for %d num\n", i+1);
17+
scanf("%d", &cnums[i].real);
18+
19+
printf("Enter the complex value for %d num\n", i+1);
20+
scanf("%d", &cnums[i].complex);
21+
}
22+
for(int i=0; i<5; i++){
23+
display(cnums[i]);
24+
}
25+
return 0;
26+
}

0 commit comments

Comments
 (0)