Skip to content

Commit 28f34e5

Browse files
committed
Format code in this file
1 parent 7dfe892 commit 28f34e5

File tree

1 file changed

+85
-83
lines changed

1 file changed

+85
-83
lines changed

solve_problem.c

Lines changed: 85 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@
33

44
#include <stdio.h>
55
void string(char arr[]);
6-
int main(){
7-
char firstName [] = "coder";
8-
char lastName [] = "Boy";
6+
int main()
7+
{
8+
char firstName[] = "coder";
9+
char lastName[] = "Boy";
910
string(firstName); // function call
10-
string(lastName); // last name
11+
string(lastName); // last name
1112
return 0;
1213
}
1314
// function Definition
14-
void string(char arr[]){
15-
for (int i = 0; arr[i] != '\0'; i++) // spacial in loop => arr[i] | for string
15+
void string(char arr[])
16+
{
17+
for (int i = 0; arr[i] != '\0'; i++) // spacial in loop => arr[i] | for string
1618
{
17-
printf("%c" , arr[i]);
19+
printf("%c", arr[i]);
1820
}
19-
printf("\n");
20-
21+
printf("\n");
2122
}
2223

2324
// 👉👉 🔹🔹 Question 2️⃣ Ask the user to enter their firstName & print in back to them
2425
// 🌟also try this with their fullName
2526

2627
#include <stdio.h>
27-
int main(){
28-
char name[20] ;
29-
printf("Enter Your Firstname : ");
30-
scanf("%s" , name);
31-
printf("Your name is %s " , name);
32-
char str[100] ;
33-
fgets(str , 100 , stdin);
28+
int main()
29+
{
30+
char name[20];
31+
printf("Enter Your Firstname : ");
32+
scanf("%s", name);
33+
printf("Your name is %s ", name);
34+
char str[100];
35+
fgets(str, 100, stdin);
3436
puts(str);
3537
return 0;
3638
}
@@ -40,96 +42,97 @@ printf("Your name is %s " , name);
4042
#include <stdio.h>
4143
int lengthStr(char arr[]);
4244

43-
int main(){
45+
int main()
46+
{
4447
char name[100];
45-
fgets(name , 100 , stdin) ;
46-
printf("Length is %d" , lengthStr(name));
48+
fgets(name, 100, stdin);
49+
printf("Length is %d", lengthStr(name));
4750
printf("\n");
4851
return 0;
4952
}
5053

5154
// Fucntion Definition
52-
int lengthStr(char arr[]){
53-
int count = 0 ;
54-
for (int i = 0;arr[i] !='\0'; i++)
55+
int lengthStr(char arr[])
5556
{
56-
count++;
57-
58-
}
59-
return count-1 ;
60-
57+
int count = 0;
58+
for (int i = 0; arr[i] != '\0'; i++)
59+
{
60+
count++;
61+
}
62+
return count - 1;
6163
}
6264

6365
// 👉👉 🔹🔹 add 2.0 version of 3️⃣rd problem
6466

65-
#include <stdio.h>
66-
#include <string.h>
67-
int main(){
68-
char name[] = " Code-Lover" ;
67+
#include <stdio.h>
68+
#include <string.h>
69+
int main()
70+
{
71+
char name[] = " Code-Lover";
6972
int length = strlen(name);
70-
printf("length is %d\n" , length);
71-
return 0;
73+
printf("length is %d\n", length);
74+
return 0;
7275
}
7376
// 👉👉 🔹🔹 question 4️⃣ take a string input from the user using %c
7477

7578
#include <stdio.h>
76-
int main(){
77-
char srt[15];
78-
char ch;
79-
int i = 0;
80-
while (ch != '\n')
79+
int main()
8180
{
82-
scanf("%c" , &ch);
83-
srt[i] = ch;
84-
i++;
85-
}
86-
srt[i] = '\0';
87-
puts(srt);
81+
char srt[15];
82+
char ch;
83+
int i = 0;
84+
while (ch != '\n')
85+
{
86+
scanf("%c", &ch);
87+
srt[i] = ch;
88+
i++;
89+
}
90+
srt[i] = '\0';
91+
puts(srt);
8892

8993
return 0;
9094
}
9195

9296
#include <stdio.h>
93-
int main(){
97+
int main()
98+
{
9499
char str[120];
95100
char ch;
96101
int i = 0;
97102
while (ch != '\n')
98103
{
99-
scanf("%c" , &ch);
100-
str[i] = ch;
101-
i++;
104+
scanf("%c", &ch);
105+
str[i] = ch;
106+
i++;
102107
}
103108
str[i] = '\0';
104-
puts(str);
109+
puts(str);
105110

106111
return 0;
107112
}
108113

109-
110-
111-
112-
113114
// |🌟 ✨| salting
114115
// // 👉👉 🔹🔹 question 5️⃣ find the salted from a password entered by the user
115116
// if the salt "123" & added that the end
116117

117118
#include <stdio.h>
118119
#include <string.h>
119-
void salting(char password []);
120-
int main(){
121-
char password[100] ;
122-
scanf("%s" , password);
123-
salting(password) ;
120+
void salting(char password[]);
121+
int main()
122+
{
123+
char password[100];
124+
scanf("%s", password);
125+
salting(password);
124126

125127
return 0;
126128
}
127-
void salting(char password []){
128-
char salt [] = "123 ";
129-
char newPass[200];
130-
strcpy(newPass , password); // newPass = something
131-
strcat( newPass , salt); // new pass = something + 123 || strcat = +
132-
puts(newPass);
129+
void salting(char password[])
130+
{
131+
char salt[] = "123 ";
132+
char newPass[200];
133+
strcpy(newPass, password); // newPass = something
134+
strcat(newPass, salt); // new pass = something + 123 || strcat = +
135+
puts(newPass);
133136
}
134137

135138
// // 👉👉 🔹🔹 question 6️⃣ write a fuction named slice , which takes
@@ -164,8 +167,8 @@ void sclice(char str[], int n, int m)
164167
int countVowels(char str[]);
165168
int main()
166169
{
167-
char str [] = "Education";
168-
printf("Vowel are : %d\n" , countVowels(str)); // Function call ;
170+
char str[] = "Education";
171+
printf("Vowel are : %d\n", countVowels(str)); // Function call ;
169172
return 0;
170173
}
171174
// Function Definition
@@ -176,34 +179,33 @@ int countVowels(char str[])
176179
{
177180
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
178181
{
179-
count ++;
182+
count++;
180183
}
181184
}
182-
return count ;
185+
return count;
183186
}
184187

185-
// // 👉👉 🔹🔹question 8️⃣ check a given Character is present in a string or not
188+
// // 👉👉 🔹🔹question 8️⃣ check a given Character is present in a string or not
186189
#include <stdio.h>
187-
void checkStr(char str [] , char ch ) ;
188-
int main(){
189-
char str [] = "Coder Boy ";
190-
char ch = 'B';
191-
checkStr(str , ch);
190+
void checkStr(char str[], char ch);
191+
int main()
192+
{
193+
char str[] = "Coder Boy ";
194+
char ch = 'B';
195+
checkStr(str, ch);
192196
return 0;
193197
}
194-
void checkStr(char str [] , char ch ) {
198+
void checkStr(char str[], char ch)
199+
{
195200
for (int i = 0; str[i] != '\0'; i++)
196201
{
197-
if (str[i] == ch)
198-
{
199-
printf("Character is present \n");
200-
return ;
201-
}
202-
202+
if (str[i] == ch)
203+
{
204+
printf("Character is present \n");
205+
return;
206+
}
203207
}
204208
printf("Character is Not present \n");
205-
206-
207209
}
208210

209211
// 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟

0 commit comments

Comments
 (0)