Using the information that \'A\' - \'A\' gives 0, \'B\' - \'A\' gives 1... \'Z\'
ID: 3683683 • Letter: U
Question
Using the information that 'A' - 'A' gives 0, 'B' - 'A' gives 1... 'Z' - 'A' gives 25 a. Declare an array of 25 integers. b. Initialize all the elements to 0. c. Then using code below as a starter, go thru the two dimensional array of random characters *nd count how many of each letter you find. You do not need any if or switch statements only use 'A' - character as the index to the array of integers. d. Then print the array of counts with labels like A: 3 If there were 3 As in the array. char y[10][25]; int row, col, I, counts[25]; fillArray(y);Explanation / Answer
char y[10][25];
int row,col,i,counts[25];
fillArray(y);
//tracing through 2d array
for(row=0;row<10;row++)
{
for(col=0;col<25;col++)
{
//finding ascii value of character
i = (int)y[row][col] ;
//as ascii values start from 65 substract with 65 so that a has value 0
i=i-65;
//store the number of times every character repeats
counts[i]++;
}
}
for(i=0;i<25;i++)
//print the character and its count
printf("%c : %d ",i+65,counts[i]);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.