-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve_problem.c
More file actions
211 lines (187 loc) · 4.34 KB
/
solve_problem.c
File metadata and controls
211 lines (187 loc) · 4.34 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// / // 👉👉 🔹🔹 Question 1️⃣ create a string firstName & lastName
// to sore details of user & print all characters using a loop
#include <stdio.h>
void string(char arr[]);
int main()
{
char firstName[] = "coder";
char lastName[] = "Boy";
string(firstName); // function call
string(lastName); // last name
return 0;
}
// function Definition
void string(char arr[])
{
for (int i = 0; arr[i] != '\0'; i++) // spacial in loop => arr[i] | for string
{
printf("%c", arr[i]);
}
printf("\n");
}
// 👉👉 🔹🔹 Question 2️⃣ Ask the user to enter their firstName & print in back to them
// 🌟also try this with their fullName
#include <stdio.h>
int main()
{
char name[20];
printf("Enter Your Firstname : ");
scanf("%s", name);
printf("Your name is %s ", name);
char str[100];
fgets(str, 100, stdin);
puts(str);
return 0;
}
// 👉👉 🔹🔹 Question 3️⃣ make a program thats input s user's name & print its length;
#include <stdio.h>
int lengthStr(char arr[]);
int main()
{
char name[100];
fgets(name, 100, stdin);
printf("Length is %d", lengthStr(name));
printf("\n");
return 0;
}
// Fucntion Definition
int lengthStr(char arr[])
{
int count = 0;
for (int i = 0; arr[i] != '\0'; i++)
{
count++;
}
return count - 1;
}
// 👉👉 🔹🔹 add 2.0 version of 3️⃣rd problem
#include <stdio.h>
#include <string.h>
int main()
{
char name[] = " Code-Lover";
int length = strlen(name);
printf("length is %d\n", length);
return 0;
}
// 👉👉 🔹🔹 question 4️⃣ take a string input from the user using %c
#include <stdio.h>
int main()
{
char srt[15];
char ch;
int i = 0;
while (ch != '\n')
{
scanf("%c", &ch);
srt[i] = ch;
i++;
}
srt[i] = '\0';
puts(srt);
return 0;
}
#include <stdio.h>
int main()
{
char str[120];
char ch;
int i = 0;
while (ch != '\n')
{
scanf("%c", &ch);
str[i] = ch;
i++;
}
str[i] = '\0';
puts(str);
return 0;
}
// |🌟 ✨| salting
// // 👉👉 🔹🔹 question 5️⃣ find the salted from a password entered by the user
// if the salt "123" & added that the end
#include <stdio.h>
#include <string.h>
void salting(char password[]);
int main()
{
char password[100];
scanf("%s", password);
salting(password);
return 0;
}
void salting(char password[])
{
char salt[] = "123 ";
char newPass[200];
strcpy(newPass, password); // newPass = something
strcat(newPass, salt); // new pass = something + 123 || strcat = +
puts(newPass);
}
// // 👉👉 🔹🔹 question 6️⃣ write a fuction named slice , which takes
// a string & returns sclice from string from index n to m
#include <stdio.h>
void sclice(char str[], int n, int m);
int main()
{
char str[] = "Coder Boy";
sclice(str, 3, 6); // Function call
return 0;
}
// Function Definition
void sclice(char str[], int n, int m)
{
char newStr[45];
int j = 0;
for (int i = n; i <= m; i++, j++)
{
newStr[j] = str[i];
}
newStr[j] = '\0';
puts(newStr);
}
// // 👉👉 🔹🔹 question 7️⃣ write a function to count occurrence of vowels in a string
#include <stdio.h>
int countVowels(char str[]);
int main()
{
char str[] = "Education";
printf("Vowel are : %d\n", countVowels(str)); // Function call ;
return 0;
}
// Function Definition
int countVowels(char str[])
{
int count = 0;
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
{
count++;
}
}
return count;
}
// // 👉👉 🔹🔹question 8️⃣ check a given Character is present in a string or not
#include <stdio.h>
void checkStr(char str[], char ch);
int main()
{
char str[] = "Coder Boy ";
char ch = 'B';
checkStr(str, ch);
return 0;
}
void checkStr(char str[], char ch)
{
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] == ch)
{
printf("Character is present \n");
return;
}
}
printf("Character is Not present \n");
}
// 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟