Vectors and Matrices

Asked

Viewed 136 times

0

Write a program in C that deciphers words from a matrix that contains the values of the letters of the alphabet, as follows: A = 7, B = 8, C = 9, D = 10, E = 11, etc.Thus 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 at that part, what should I do?

  • J.Donate, what is your intention in disfiguring the questions? They do not deserve such mistreatment

1 answer

1

How 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;
}

Exit:

CADA
CADE
STACKOVERFLOW
  • Very good! Thank you

  • @J.Donate you can show your appreciation by voting and selecting the answer that meets your need

Browser other questions tagged

You are not signed in. Login or sign up in order to post.