مرحبا
كيفكم
هذي أول مشاركه لي
آمل انكم تساعدووني
انا ادرس لغه C
وعندي Sheet
وهذي الأسئله
1. Write a program that reads several strings. For each string the program should determine whether that string is a palindrome or not. A palindrome is a string that reads the same from the left and the right. For example, ABCBA is a palindrome.
2. Write a program that reads a line of text. The program should find the length of each word in the string and stores it in an array. The program should print the resulting array, and the index of the word that has the largest length. The program should also find and print the average word length.
3. Write a program that plays the game of hangman. Read the word to be guessed into the string WORD. The player must guess the letters belonging to WORD. The program should terminate when either all letters have been guessed correctly (player wins) or a specified number of incorrect guesses have been made (computer wins).
a. Hint: use the string SOLUTION to keep track of the solution so far. Initialize SOLUTION to the string of symbols ‘*’. Each time a letter in WORD is guessed, replace the corresponding ‘*’ in SOLUTION with that letter.
السؤال الأول اوكي حليته ,,
بس الثاني عقدنيييييي هو والثالث
هذي محاولاتي في السؤال الثاني وللآن مو راضي يزبط
---------------------------------------------------------
first try
#include<stdio.h>
#include<string.h>
int main()
{
char text[100];
int lens[50];
int len_all,i,largest,num_words,sum;
float ave;
printf("Enter A Line of Text Please\n");
gets(text);
len_all=strlen(text);
letter="getchar()";
while(strcmp(letter,"\0")!=0)
{
if(strcmp(letter," ")!=0)
lens++;
else
i++;
letter="getchar()";
}
num_words=i++;
for(largest=0,i=0;i<=num_words;i++)
{
if(lens>largest)
largest=i++;
sum+=lens;
}
ave=(float)sum/num_words;
printf("The length of The words is %d\n",lens);
printf("The largest length for word number %d\n",largest);
printf("The average of word length= %.2f\n",ave);
return 0;
}
--------------------------------------------------------------
Second Try
#include<stdio.h>
#include<string.h>
int main()
{
char text[100],left[100];
int lens[50];
int len_all,len_left,i,largest,num_words,sum;
float ave;
printf("Enter A Line of Text Please\n");
gets(text);
len_all=strlen(text);
left[100]=strstr(text," ");
len_left=strlen(text);
lens[0]=len_all - len_left;
for(i=1;len_left!=0;i++)
{
len_all=strlen(left);
left[100]=strstr(left," ");
len_left=strlen(left)-1;
lens=len_all - len_left;
}
num_words=i-2;
for(largest=0,i=1;i<=num_words;i++)
{
if(lens>largest)
largest=i++;
sum+=lens;
}
ave=(float)sum/num_words;
printf("The length of The words is %d\n",lens);
printf("The largest length for word number %d\n",largest);
printf("The average of word length= %.2f\n",ave);
return 0;
}
-----------------------------------------------------------------------------------------
ياريت تساعدوووني
لو بأي سؤال فيهم
المشكله لازمن اسلمه السبت
عارفه اني مهمله بس والله كان عندي اختبارات فأجلته
الله يخليكم الله يخليكم ساعدووني
باي
