Strings Eaxmples
Strings Eaxmples
Scenario:
Find how many times a specific character appears in a given string.
Program:
#include <stdio.h>
int main() {
int count = 0;
scanf("%s", str);
if (str[i] == target) {
count++;
return 0;
}
. Compare Two Strings
Scenario:
Check if two strings are equal or not.
Program:
#include <stdio.h>
int main() {
int areEqual = 1;
scanf("%s", str1);
scanf("%s", str2);
if (areEqual) {
} else {
return 0;
}
Reverse a String
Scenario:
Write a program to reverse the characters of a given string.
Program:
#include <stdio.h>
int main()
int length = 0;
scanf("%s", str);
// Calculate length
length++;
return 0;
}
Count Vowels and Consonants
Scenario:
Count the number of vowels and consonants in a given string.
Program:
#include <stdio.h>
int main() {
char str[100];
scanf("%s", str);
char ch = str[i];
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
vowels++;
else
consonants++;
return 0;
}
**************************************************************************************
Scenario:
Check if a password is strong. A password is strong if it contains:
Username Validation
Scenario:
Validate a username based on these rules:
Scenario:
Count the number of words in a given sentence. Words are separated by spaces.
Scenario:
Find how many times a specific character appears in a string.
**************************************************************************************