Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <string.h>
- #define N 20
- typedef struct conductor{
- char nombre[50];
- int edad;
- char matricula[N];
- }datos_conductor;
- datos_conductor introducir_datos(){
- datos_conductor a;
- printf("Nombre conductor:\n");
- gets(a.nombre);
- printf("Matricula:\n");
- gets(a.matricula);
- printf("Edad:\n");
- scanf("%d",&a.edad);
- return a;
- }
- bool coincide(datos_conductor c){
- int suma = 0;
- bool valor = false;
- for(int i = 0; i < N; i++){
- if(c.matricula[i] >='0' && c.matricula[i] <='9'){
- suma = suma + c.matricula[i] -'0';
- }
- }
- if (suma == c.edad) {
- valor = true;
- }
- return valor;
- }
- bool iniciales(datos_conductor c){
- int suma = 0;
- bool valor = false;
- for (int i = 0; i < N; i++){
- for(int j = 0; j < N; j++){
- if (c.nombre[i] >= 'A' && c.nombre[i] <= 'Z') {
- if (c.matricula[j] == c.nombre[i]) {
- valor = true;
- }
- }
- }
- }
- return valor;
- }
- int main(){
- int suma = 0;
- bool retorno = 0;
- datos_conductor c1;
- c1 = introducir_datos();
- printf("\n%s",c1.matricula);
- coincide(c1);
- retorno = coincide(c1);
- if (retorno == true){
- printf("\nValor true, la suma de la matricula es igual a la edad");
- } else{
- printf("\nValor false, la suma de la matricula no es igual a la edad");
- }
- iniciales(c1);
- retorno = iniciales(c1);
- if (retorno == true){
- printf("\nValor true, las iniciales coinciden");
- } else{
- printf("\nValor false, las iniciales no coinciden");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment