Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

EED 1010 LaboratoryWork II

Name: Hasan Furkan Çolak


ID: 2018502090
Date: 6.4.2021

Task 1
#include<stdio.h>

#include<string.h>

int anagram(char word1[],char word2[]); //prototype of function

int main()

int i,j,k=0,x,y,z;

const char *word1[50]={'\0'}; //strings for words

const char *word2[50]={'\0'};

printf("Enter two words ( SMALL LETTERS ONLY ) to find out they are anagram or not.\n\n");

printf("Word #1: ");

scanf("%s",word1); //take first word

printf("Word #2: ");

scanf("%s",word2); //take second word

x=strlen(word1); //determine lenghts of strings

y=strlen(word2);

k=strcmp(word1,word2); //compare strings

if(k==0){

printf("\nWords are same.\n\n");

else if(x!=y){

printf("\nWords has different lenghts.\n\n");

else{
z=anagram(word1,word2); //call function

if(z==1){ //control statement for function return value

printf("\n%s and %s are anagram words.\n\n",word1,word2);

}else{

printf("\n%s and %s are NOT anagram words.\n\n",word1,word2);

int anagram(char word1[],char word2[]) //head of prototype

int a,b,c,d,e;

c=strlen(word1); //determine lenght of string

int letters1[50]={0},letters2[50]={0};

for(a=0;a<c;a++){ //loop for compare letters

for(b=0;b<c;b++){

e=letters2[a]; //character varriable for keep current value

if(word1[a]==word1[b]){ //count letters in word

letters1[a]++;

if(word1[a]==word2[b]){ //compare letters of two word

letters2[a]++;

b=0;

for(a=0;a<c;a++){ //check letters numbers


if(letters1[a]==letters2[a]){

b++;

if(b==c){ //return 1 if word has same numbers of letters

return 1;

Task 2
#include<stdio.h>

#include<string.h>

void reverse(char *); //prototype of function

int main()

char str[100] = {'\0'}; //define array

const char s[2] = " "; //define space character

char *token; //pointer

printf("Enter a sentence:\n");

gets(str); //take string from user

printf("\nSentence with reverse words:\n");

/* get the first token */

token = strtok(str, s);


/* walk through other tokens */

while( token != NULL ) {

reverse(token); //call function

token = strtok(NULL, s);

printf("\n\n");

void reverse(char *s){ //head of function

int k = strlen(s); //determine lenght of string

while (k >= 0){ //loop for print string

printf("%c", s[k]);

k--;

printf(" ");

}
Task III
My code not working properly but its work. Error is in main for loop.

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<time.h>

#define N 20

const char* word_database[] = {"literature", "scholar",

"enormous", "influence", "publication", "pioneer", "telephone",

"orchestra", "teacher", "member", "final", "phonograph",

"executed", "oldest", "people", "requiring", "screwdriver",

"intelligent", "different", "striking"};

int check(char word[],char line[],char c);

int main(){

int n,m,j,a=0,b=0,d,ck,w;

char line[50];

char word[50];

char c;

for(m=0;m<50;m++){

line[m]='_';

srand(time(NULL));

n=rand()%20;

printf("%s",word_database[n]);

m=strlen(word_database[n]);
printf("\n*****HANGMAN GAME*****\n");

printf("Guess the word letter by letter.\n");

for(j=0;j<m;j++){

printf("%c",line[j]);

strcpy(word,word_database[n]);

for(a=0;a<10;a++){

printf("\n\nGuess:");

scanf("%c",&c);

ck=check(word,line,c);

if(ck>=1){

printf("\nRight Guess!\n");

for(d=0;d<m;d++){

printf("%c",line[d]);

}if(ck==0){

printf("\nTry Again!\n");

for(w=0;w<m;w++){

printf("%c",line[w]);

}
printf("\n\n\n");

int check(char word[],char line[],char c)

int b=0;

int k,z=0;

k=strlen(word);

for(b=0;b<k;b++){

if(word[b]==c){

line[b]=c;

z++;

if(z>0){

return z;

}else{

return 0;

You might also like