Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C program Make sure it runs please and well documented You already have got some

ID: 3872117 • Letter: C

Question

C program Make sure it runs please and well documented

You already have got some idea about Memory Hierarchy. In the memory hierarchy if the processoricpu needs some data, it searches the data in the following way: Cache->Memory->Disk In this assignment you have to implement some kind of demo memory hierarchy using c code Assume that you have cache, memory and disk of size 4 blocks, 16 blocks and 256 blocks respectively. Each block of the cache, memory and disk contains 4 bytes of data (which is equivalent of the size of one integer). So, whenever processor requests for some data, the transfer is made in blocks To incorporate the scenario into your demo memory hierarchy code, you can define your cache, memory and disk in terms of array. Say for example: Int cachel4] Int memory[16]: Int disk[2561 Initially only the disk would have some value. The value of each array would be: disk: Value 01 2 3 4 5 6 7 8 9 1011 12255 memory Index 0 1 2 3 4 5 6 7 8 910 11 12 13 14 15 Value cache Index

Explanation / Answer

#include <stdio.h>
# include <stdbool.h>
bool CompareString1(char *string1, char *string2)
{
int count1[255] = {0};
int count2[255] = {0};
int i;
for (i = 0; string1[i] && string2[i]; i++)
{
count1[string1[i]]++;
count2[string2[i]]++;
}
if (string1[i] || string2[i])
return false;
for (i = 0; i < 255; i++)
if (count1[i] != count2[i])
return false;
return true;
}
int CompareString2(char *string1, char *string2)
{
int c1[26] = {0}, c2[26] = {0}, c = 0;
while (string1[c] != '')
{
c1[string1[c]-'a']++;
c++;
}
c = 0;
while (string2[c] != '')
{
c2[string2[c]-'a']++;
c++;
}
for (c = 0; c < 26; c++)
{
if (c1[c] != c2[c])
return 0;
}
return 1;
}
int main()
{
char string1[] = "bbbcccbaaba";
char string2[] = "abbbcbccbab";
if ( CompareString2(string1, string2) )
printf("Both the string contain same number of character with in them");
else
printf("Both the string does not contain same number of character with in them");
return 0;
}