You are on page 1of 8

22K-4060 (BS-AI Section A)

Ali Suleman (Assignment # 3)


Q#1 Code:
C-Script
#include <stdio.h>
#include <string.h>
int main()
{
int i, j, k,m;
char arr[5][6], ID[8], searchit[8],score=0,row,col,cols;

printf("Enter your Fast Roll#: ");


gets (ID);

int lenID = strlen(ID);


for(i=0;i<5;i++)
{
for(j=0;j<6;j++)
{
if(i==4 && j<4)
{
char idtoken = ID[(lenID-4)+j];
arr[i][j] = idtoken;
}
else{
char randChar = rand()%26+'A';
arr[i][j] = randChar;
}
}
}

printf("Randomnly Generated Array is : \n");


for(i=0;i<5;i++)
{
for(j=0;j<6;j++)
{
printf("%c ",arr[i][j]);
}
printf("\n");
}

while(1)
{

printf("\nEnter any string: ");


gets(searchit);
int x = strlen(searchit), y=0, flag;
int found=0,match=0;
// if searchit = END then it will repopulate the ArraY. :))
if(!strcmp(searchit,"END"))
{
for(i=0;i<5;i++)
{
for(j=0;j<6;j++)
{
if(i==4 && j<4)
{
char idtoken = ID[(lenID-4)+j];
arr[i][j] = idtoken;
}
else{
char randChar = rand()%26+'A';
arr[i][j] = randChar;
}
}
}
for(i=0;i<5;i++)
{
for(j=0;j<6;j++)
{

printf("%c ",arr[i][j]);
}
printf("\n");
}
break;
}

for(row=0;row<5;row++)
{
for(cols=0;cols<=6-x;i++){
for(col=cols;col<x+cols;col++){
if(arr[row][col]==searchit[col-cols])
{
match++;
}
}
if(match==x)
{
found++;
}
match=0;
}
}

if(found>0)
{
score++;
printf("\n%s found!! Your score == %d",searchit,score);
}
else
{
score--;
printf("\n%s not found!! Your score == %d",searchit,score);
}

}
}

Output:
Q#2 Code:
C-Script
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char s[1000], ID[8], store[1500];
printf("Enter your ID:");
gets(ID);
strcat(ID," ");
printf("Type Message for Encryption: ");
strcat(store,ID);
gets(s);

int i = 0, c = 1;

for(i=0;s[i]!='\0';i++)
{
if(s[i]==' ')
c++;
}

// printf("There are %d words in your string: ",c);


char *ptr = strtok(s," ");
int j;
while(ptr!=NULL)
{
char x[100], z[100]; int y[100];
strcpy(x,ptr);
int length = strlen(x);

// encryption body for consonant starting && sch strating


if(x[0]=='a' || x[0]=='e' || x[0]=='i' || x[0]=='o' || x[0]=='u' || x[0]=='A' || x[0]=='E' ||
x[0]=='I' || x[0]=='O' || x[0]=='U')
{
strcat(x,"way ");
}

else if(x[0]!='a' && x[0]!='e' && x[0]!='i' && x[0]!='o' && x[0]!='u')
{
if(x[0]=='s' && x[1]=='c' && x[2]=='h')
{
x[1]='k';
for(i=0;i<length;i++)
{
if(x[i]=='h')
for(j=i;j<length;j++)
{
x[j] = x[j+1];
}
}
length = length-1;

for(i=0;i<2;i++)
{
char temp = x[0];
for(j=0;j<length-1;j++)
{
x[j] = x[j+1];
}
x[length-1] = temp;
}
strcat(x,"ay ");
}
else
{
for(i=0;i<2;i++)
{
char temp = x[length-1];
for(j=length-1;j>0;j--)
{
x[j] = x[j-1];
}
x[0] = temp;
}

strcat(x,"ay ");
}
}

strcat(store,x);
ptr = strtok(NULL, " ");
}
printf("decrypted message is: ");
puts(store);
}
Output:

You might also like