Skip to content
Snippets Groups Projects
Commit ad38d800 authored by Florian Burgener's avatar Florian Burgener
Browse files

Validation exercice 1

parent f3940e21
Branches
No related tags found
No related merge requests found
/**
* @file main.c
* @author Prénom Nom
* @author Florian Burgener
* @brief Exercice 1
* @version 1.0
* @date 2021-12-07
......@@ -9,31 +9,32 @@
*
*/
#include <math.h>
#include <stdbool.h>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
char str1[100];
char str2[100];
// 80 characters + 1 (null character).
char str1[81];
char str2[81];
scanf("%s", str1);
scanf("%s", str2);
printf("%s\n", str1);
if (strlen(str1) != strlen(str2)) {
// Strings do not have the same length.
printf("\ndistance: -1\n");
return EXIT_FAILURE;
}
int32_t distance = 0;
// Calculation of the distance.
for (int32_t i = 0; i < (int32_t)strlen(str1); i += 1) {
distance += abs(toupper(str1[i]) - toupper(str2[i]));
}
printf("\ndistance: %d\n", distance);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment