Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Week 4/7 SOLUTIONS
- PROBLEM 1
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- char ary[] = "2019";
- char* str = NULL;
- char* str2 = "2021";
- printf("%s %d\n", ary, (int)strlen(ary));
- printf("%s %d\n", str, (int)strlen(str));
- printf("%s %d", str2, (int)strlen(str2));
- return 0;
- }
- PROBLEM 2
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- char ary[] = "Godzilla is gonna win";
- //char* ary = "Godzilla is gonna win";
- for (int i = strlen(ary); i >= 0; i--){
- printf("%c", ary[i]);
- }
- return 0;
- }
- PROBLEM 2B
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- char ary[] = "Godzilla is gonna win.";
- printf("%s", ary);
- return 0;
- }
- Problem 3
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- char str[80] = "";
- printf("Enter in a sentence up to 80 characters: ");
- fgets(str, 80, stdin);
- printf("\n");
- printf("Here is your sentence: %s", str);
- return 0;
- }
- Problem 4
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int main(void)
- {
- char str[80] = "";
- printf("Enter in a sentence up to 80 characters: ");
- fgets(str, 80, stdin);
- printf("\n");
- printf("Here is your sentence: %s", str);
- for (int i = 0; i < strlen(str); i++){
- if (isupper(str[i])){
- printf("%c is Uppercase\n", str[i]);
- }
- else if (islower(str[i])){
- printf("%c is Lowercase\n", str[i]);
- }
- else{
- printf("\n");
- }
- }
- return 0;
- }
- Problem 4B
- [Don't have one lol]
Advertisement
Add Comment
Please, Sign In to add comment