/* קלט: משפט באנגלית פלט: האות האחרונה במילה הראשונה ומספר המילים במשפט */ using System; public class HowManyWords { public static void Main() { string sentence; int placeOfLastLetter; int numOfSpaces = 0; int numOfWords; Console.WriteLine("Enter a sentence, with exactly one " + " space between words: "); sentence = Console.ReadLine(); //מניית הרווחים במשפט for (int i = 0; i < sentence.Length; i++) if (sentence[i] == ' ') numOfSpaces++; numOfWords = numOfSpaces + 1; // מציאת מקומו של הרווח הראשון if (numOfWords == 1) placeOfLastLetter = sentence.Length - 1; else placeOfLastLetter = sentence.IndexOf(' ') - 1; Console.WriteLine("The last letter of the first word is: {0}" , sentence[placeOfLastLetter]); //כמה מילים במשפט Console.WriteLine("There are {0} words", numOfWords); }//Main }// class HowManyWords