|
1 | 1 | // / // 👉👉 🔹🔹 Question 1️⃣ create a string firstName & lastName |
2 | 2 | // to sore details of user & print all characters using a loop |
3 | 3 |
|
4 | | -#include <stdio.h> |
5 | | -void string(char arr[]); |
6 | | -int main(){ |
7 | | - char firstName [] = "coder"; |
8 | | - char lastName [] = "Boy"; |
9 | | - string(firstName); // function call |
10 | | - string(lastName); // last name |
11 | | - return 0; |
12 | | -} |
| 4 | +// #include <stdio.h> |
| 5 | +// void string(char arr[]); |
| 6 | +// int main(){ |
| 7 | +// char firstName [] = "coder"; |
| 8 | +// char lastName [] = "Boy"; |
| 9 | +// string(firstName); // function call |
| 10 | +// string(lastName); // last name |
| 11 | +// return 0; |
| 12 | +// } |
13 | 13 | // function Definition |
14 | | -void string(char arr[]){ |
15 | | - for (int i = 0; arr[i] != '0円'; i++) // spacial in loop => arr[i] | for string |
16 | | - { |
17 | | - printf("%c" , arr[i]); |
18 | | - } |
19 | | - printf("\n"); |
| 14 | +// void string(char arr[]){ |
| 15 | +// for (int i = 0; arr[i] != '0円'; i++) // spacial in loop => arr[i] | for string |
| 16 | +// { |
| 17 | +// printf("%c" , arr[i]); |
| 18 | +// } |
| 19 | +// printf("\n"); |
20 | 20 |
|
21 | | -} |
| 21 | +// } |
22 | 22 |
|
23 | 23 | // 👉👉 🔹🔹 Question 2️⃣ Ask the user to enter their firstName & print in back to them |
24 | 24 | // 🌟also try this with their fullName |
25 | 25 |
|
26 | 26 |
|
27 | | -#include <stdio.h> |
28 | | -int main(){ |
| 27 | +// #include <stdio.h> |
| 28 | +// int main(){ |
29 | 29 | // char name[20] ; |
30 | 30 | // printf("Enter Your Firstname : "); |
31 | 31 | // scanf("%s" , name); |
32 | 32 | // printf("Your name is %s " , name); |
33 | | - char str[100] ; |
34 | | - fgets(str , 100 , stdin); |
35 | | - puts(str); |
| 33 | +// char str[100] ; |
| 34 | +// fgets(str , 100 , stdin); |
| 35 | +// puts(str); |
| 36 | +// return 0; |
| 37 | +// } |
| 38 | + |
| 39 | +// 👉👉 🔹🔹 Question 3️⃣ make a program thats input s user's name & print its length; |
| 40 | + |
| 41 | + |
| 42 | +#include <stdio.h> |
| 43 | +int lengthStr(char arr[]); |
| 44 | + |
| 45 | +int main(){ |
| 46 | + char name[100]; |
| 47 | + fgets(name , 100 , stdin) ; |
| 48 | + printf("Length is %d" , lengthStr(name)); |
| 49 | + printf("\n"); |
36 | 50 | return 0; |
37 | 51 | } |
38 | 52 |
|
| 53 | +// Fucntion Definition |
| 54 | +int lengthStr(char arr[]){ |
| 55 | +int count = 0 ; |
| 56 | +for (int i = 0;arr[i] !='0円'; i++) |
| 57 | +{ |
| 58 | + count++; |
| 59 | + |
| 60 | +} |
| 61 | +return count-1 ; |
| 62 | + |
| 63 | +} |
| 64 | + |
39 | 65 |
|
40 | 66 | // #include <stdio.h> |
41 | 67 | // int main(){ |
|
0 commit comments