seergiomv

Ejercicio 32.4 +-

Jan 9th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #define N 20
  5. typedef struct conductor{
  6.     char nombre[50];
  7.     int edad;
  8.     char matricula[N];
  9. }datos_conductor;
  10. datos_conductor introducir_datos(){
  11.     datos_conductor a;
  12.     printf("Nombre conductor:\n");
  13.     gets(a.nombre);
  14.     printf("Matricula:\n");
  15.     gets(a.matricula);
  16.     printf("Edad:\n");
  17.     scanf("%d",&a.edad);
  18.     return a;
  19. }
  20. bool coincide(datos_conductor c){
  21.     int suma = 0;
  22.     bool valor = false;
  23.     for(int i = 0; i < N; i++){
  24.         if(c.matricula[i] >='0' && c.matricula[i] <='9'){
  25.             suma = suma + c.matricula[i] -'0';
  26.         }
  27.     }
  28.     if (suma == c.edad) {
  29.         valor = true;
  30.     }
  31.     return valor;
  32. }
  33. bool iniciales(datos_conductor c){
  34.     int suma = 0;
  35.     bool valor = false;
  36.     for (int i = 0; i < N; i++){
  37.         for(int j = 0; j < N; j++){
  38.             if (c.nombre[i] >= 'A' && c.nombre[i] <= 'Z') {
  39.                 if (c.matricula[j] == c.nombre[i]) {
  40.                     valor = true;
  41.                 }
  42.             }
  43.         }
  44.     }
  45.     return valor;
  46. }
  47. int main(){
  48.     int suma = 0;
  49.     bool retorno = 0;
  50.     datos_conductor c1;
  51.     c1 = introducir_datos();
  52.     printf("\n%s",c1.matricula);
  53.     coincide(c1);
  54.     retorno = coincide(c1);
  55.     if (retorno == true){
  56.         printf("\nValor true, la suma de la matricula es igual a la edad");
  57.     } else{
  58.         printf("\nValor false, la suma de la matricula no es igual a la edad");
  59.     }
  60.     iniciales(c1);
  61.     retorno = iniciales(c1);
  62.     if (retorno == true){
  63.         printf("\nValor true, las iniciales coinciden");
  64.     } else{
  65.         printf("\nValor false, las iniciales no coinciden");
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment