-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve_problem.c
More file actions
165 lines (138 loc) · 3.64 KB
/
solve_problem.c
File metadata and controls
165 lines (138 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// ================================================
// * Language: C
// * Topic: Pointer
// * solve practice Problem
// =================================================
// // 👉👉 🔹🔹 Question 1️⃣ - write a program to enter price of 3 times &
// print their final cost with gst
#include <stdio.h>
int main()
{
float price[3];
printf("Enter3 price : ");
scanf("%f", &price[0]);
scanf("%f", &price[1]);
scanf("%f", &price[2]);
printf("Total price 1 = %f\n", price[0] + (0.18 * price[0]));
printf("Total price 2 = %f\n", price[1] + (0.18 * price[1]));
printf("Total price 3 = %f\n", price[2] + (0.18 * price[2]));
return 0;
}
// 👉👉 🔹🔹 Question 1️⃣ - write a program to enter price of 3 times &
// print their final cost with gst
// ========================== versoin 2.0 =======================
#include <stdio.h>
int main()
{
float price[3];
printf("Enter 1st price :");
scanf("%f", &price[0]);
printf("Enter 2nd price :");
scanf("%f", &price[1]);
printf("Enter 3rd price :");
scanf("%f", &price[2]);
printf("Total price 1 = %f\n", price[0] + (0.18 * price[0]));
printf("Total price 2 = %f\n", price[1] + (0.18 * price[1]));
printf("Total price 3 = %f\n", price[2] + (0.18 * price[2]));
return 0;
}
// 👉👉 🔹🔹 Question 2️⃣ write a function to count the numbers of odd numbers in array
#include <stdio.h>
int count(int arr[], int n);
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7};
printf("%d\n", count(arr, 7));
return 0;
}
// Function Definition
int count(int arr[], int n)
{
int count = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] % 2 != 0)
{
count++;
}
}
return count;
}
// 👉👉 🔹🔹 Question 3️⃣ write a function to reverse an array
#include <stdio.h>
void reverse(int arr[], int n);
void printArr(int arr[], int n);
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6};
reverse(arr, 6); // function call
printArr(arr, 6); // function call
return 0;
}
// function definition
void printArr(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
printf("%d\t", arr[i]);
}
printf("\n");
}
// function definition
void reverse(int arr[], int n)
{
for (int i = 0; i < 5 / 2; i++)
{
int firstValue = arr[i];
int lastValue = arr[n - i - 1];
arr[i] = lastValue;
arr[n - i - 1] = firstValue;
}
}
// 👉👉 🔹🔹 4️⃣ Question write a program to store the first n fibonacci numbers
#include <stdio.h>
int main()
{
int n;
printf("Enter Number > 2 :");
scanf("%d", &n);
int fibo[n];
fibo[0] = 0;
fibo[1] = 1;
for (int i = 2; i < n; i++)
{
fibo[i] = fibo[i - 1] + fibo[i - 2];
printf("%d\t", fibo[i]);
}
printf("\n");
return 0;
}
// 👉👉 🔹🔹 5️⃣ create a 2D array , storing the tables 2& 3
#include <stdio.h>
void soteTable(int arr[][10], int n, int m, int number);
int main()
{
int tables[2][10];
soteTable(tables, 0, 10, 2); // function call
soteTable(tables, 1, 10, 3); // Function call
for (int i = 0; i < 10; i++)
{
printf("%d\t", tables[0][i]);
}
printf("\n");
for (int i = 0; i < 10; i++)
{
printf("%d\t", tables[1][i]);
}
printf("\n");
return 0;
}
// Function Diefinition
void soteTable(int arr[][10], int n, int m, int number)
{
for (int i = 0; i < m; i++)
{
arr[n][i] = number * (i + 1);
}
}
// 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟