Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WARMUP SOLUTION
- #include <stdio.h>
- #include <string.h>
- int main(){
- char str[20];
- printf("Enter in your first name: ");
- scanf("%s", str);
- printf("%s\n", str);
- return 0;
- }
- PROBLEM #1 SOLUTION
- #include <stdio.h>
- #include <string.h>
- int main(){
- char fName[25];
- char lName[25];
- int age;
- printf("Enter in your first name, last name, and age: \n");
- scanf("%s %s %d", fName, lName, &age);
- printf("%s %s %d\n", fName, lName, age);
- return 0;
- }
- PROBLEM #2 SOLUTION
- #include <stdio.h>
- #include <string.h>
- int main(){
- char ary1[40];
- char ary2[40];
- char ary3[40];
- char ary4[120];
- printf("Enter in your first name: ");
- fgets(ary1, 40, stdin);
- printf("Enter in your middle name: ");
- fgets(ary2, 40, stdin);
- printf("Enter in your last name: ");
- fgets(ary3, 40, stdin);
- strcpy(ary4, ary1);
- strcat(ary4, ary2);
- strcat(ary4, ary3);
- printf("%s%d\n", ary4, (int) strlen(ary4));
- return 0;
- }
- PROBLEM #3 SOLUTION
- #include <stdio.h>
- #include <string.h>
- int main(){
- char ary[] = "Mary had a little lamb";
- for(int i = strlen(ary); i >= 0; i--){
- printf("%c", ary[i]);
- }
- return 0;
- }
- PROBLEM #4 SOLUTION
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int main(){
- char ary[81];
- int size;
- printf("Enter in a sentence: ");
- fgets(ary, 80, stdin);
- ary[strcspn(ary, "\n")] = 0;
- size = sizeof(ary);
- for (int i = 0; i < size; i++){
- if (!isupper(ary[i])){
- ary[i] = toupper(ary[i]);
- }
- }
- printf("%s\n", ary);
- return 0;
- }
- PROBLEM #5 SOLUTION
- #include <stdio.h>
- #include <string.h>
- int main(void) {
- char userInput[50]; // User numbers
- int i;
- int charCount;
- fgets(userInput, 50, stdin);
- charCount = 0;
- for (i = 0; i < strlen(userInput); ++i) {
- if ( (userInput[i] != ' ') && (userInput[i] != '.') && (userInput[i] != ',')
- && (userInput[i] != '!') && (userInput[i] != '\n')) {
- charCount = charCount + 1;
- }
- }
- printf("%d\n",charCount);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment