Skip to content

Instantly share code, notes, and snippets.

@leovarmak
Created February 17, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leovarmak/5c67b0c54be6ec2bf19a2443538fade9 to your computer and use it in GitHub Desktop.
Save leovarmak/5c67b0c54be6ec2bf19a2443538fade9 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int main(){
char string[100];
char alphabets[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int i, j, first_string_size = 0, second_string_size = 0;
printf("\nEnter first string: ");
fgets(string, sizeof string, stdin);
for (i = 0; i < strlen(string); i++){
for (j = 0; j < sizeof alphabets; j++) {
if (string[i] == alphabets[j]) {
first_string_size = j + 1 + first_string_size;
}
}
}
printf("Enter second string: ");
fgets(string, sizeof string, stdin);
for (i = 0; i < strlen(string); i++){
for (j = 0; j < sizeof alphabets; j++) {
if (string[i] == alphabets[j]) {
second_string_size = j + 1 + second_string_size;
}
}
}
if(first_string_size > second_string_size){
printf("\nFirst string is bigger\n");
} else if (first_string_size == second_string_size) {
printf("\nBoth are of same size\n");
} else {
printf("\nSecond string is bigger\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment