Write a program that uses an array to count and report the frequency of occurren
ID: 3547012 • Letter: W
Question
Write a program that uses an array to count and report the frequency of occurrence of the letters in the text
document provided with this lab (you can code this into your program as a String).
The text was originally written in English; spaces and punctuation have been removed, and the text was then
encrypted with a simple substitution cipher.
a: Decrypt the text
b: Write a program that encrypts a string of text using a cipher of your own design.
For this option, you must also provide a decryption method.
The text is as follows:
Explanation / Answer
#include<stdio.h>
int main()
{
char string[1000];
int array[26]= {0};
int i,j,x,y;
scanf("%s",string);
int z=strlen(string);
for(i=0; i<z; i++)
{
x=(int)string[i];
y=x-65;
array[y]++;
}
for(j=0; j<26; j++)
printf("occurences of %c are : %d ",j+65,array[j]);
//encryption
for(i=0; i<z; i++)
{
string[i]=string[i]+1;
}
printf(" Encrypted string is : %s",string);
//Decryption
for(i=0; i<z/2; i++)
{
string[i]=string[i]-1;
}
printf(" Decrypted string is : %s",string);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.