0% found this document useful (0 votes)
9 views3 pages

Activity 3 - Take Home (C Libraries) - PEREZ

Uploaded by

Charles Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Activity 3 - Take Home (C Libraries) - PEREZ

Uploaded by

Charles Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ITE 13 Take Home Activity

Name: Charles T. Perez Section: DQR1 Score:

Direction:
A. First, read this site and familiarize each function available in the library.
 string.h
 ctype.h
 stdlib.h
B. Create a program as directed in the problem. Provide the code in the box.

Problems:

1. Create a program that sorts words in alphabetical order.


Example:
Words in Array: Event, Fine, Abacus, Ease, Ziplock
Sorted: Abacus, Ease, Event, Fine, Ziplock
#include <stdio.h>

#include <string.h>

int main() {

char words[5][100];

char temp[100];

printf("Enter 5 words:\n");

for (int i = 0; i < 5; i++) {

printf("Word %d: ", i + 1);

scanf("%s", words[i]);

for (int i = 0; i < 4; i++) {

for (int j = i + 1; j < 5; j++) {

if (strcmp(words[i], words[j]) > 0) {

strcpy(temp, words[i]);

strcpy(words[i], words[j]);

strcpy(words[j], temp);

printf("\nSorted words:\n");

for (int i = 0; i < 5; i++) {

printf("%s\n", words[i]);

return 0;

}
2. Create a program that check if a password is strong or not. A strong
password contains at least 1 uppercase, no space, 3 digits, and length is 8
above.
Example:
Password: abcdE123x
Strong password!
#include <stdio.h>

#include <string.h>

#include <ctype.h>

int main() {

char password[100];

int hasUppercase = 0, digitCount = 0, length = 0, hasSpace = 0;

printf("Enter a password: ");

scanf("%s", password);

length = strlen(password);

for (int i = 0; i < length; i++) {

if (isupper(password[i])) {

hasUppercase = 1;

if (isdigit(password[i])) {

digitCount++;

if (isspace(password[i])) {

hasSpace = 1;

if (length >= 8 && hasUppercase && digitCount >= 3 && !hasSpace) {

printf("Strong password!\n");

} else {

printf("Weak password! A strong password has atleast 1 uppercase letter, 3 digits, no spaces, and is 8 characters or more.\n");

return 0;

3. Create a program that adds all the digit that can be found in a string
inputted by the user.
Example:
Enter String: 1 little 2 little 3 little Indians, 4 little 5 little 7 little Indians
Sum of all found digits: 22

#include <stdio.h>

#include <string.h>

You might also like