Vectors and Matrices [closed]

0

Write a program in C that decodes words from an array that contains the values of the letters of the alphabet, as below: A = 7, B = 8, C = 9, D = 10, E = 11, etc. , the code: (a) 9 7 10 7, that is to say EVERY b) 9 7 10 11, that is to say CADE '

#include <stdio.h>

int main() {
    int arrayLetras[10];
    int i = 0;
    int j;
    char chrEspaco = ' ';

    while(chrEspaco!='\n'){ 
        scanf("%d%c",&arrayLetras[i++],&chrEspaco);
    }
    j = 0;

    while(j < i) {
        printf("%c ",arrayLetras[j]);
        j++;
    }
}

I stopped in this part, what should I do?

    
asked by anonymous 26.06.2017 / 20:37

1 answer

1

What about:

#include <stdio.h>

#define sizeof_array(a)   (sizeof(a)/sizeof(a[0]))

void decifrar( int matriz[], int tam )
{
    int i = 0;

    for( i = 0; i < tam; i++ )
        printf( "%c", 'A' - 7 + matriz[i] );

    printf( "\n" );
}


int main( int argc, char * argv[] )
{
    int palavra1[] = { 9, 7, 10, 7 };
    int palavra2[] = { 9, 7, 10, 11 };
    int palavra3[] = { 25, 26, 7, 9, 17, 21, 28, 11, 24, 12, 18, 21, 29 };

    decifrar( palavra1, sizeof_array(palavra1) );
    decifrar( palavra2, sizeof_array(palavra2) );
    decifrar( palavra3, sizeof_array(palavra3) );

    return 0;
}

Output:

CADA
CADE
STACKOVERFLOW
    
26.06.2017 / 22:01