define an array with 10 words &takes a letter as input. Write a progto iterate through the array & output words contain no match | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

define an array with 10 words &takes a letter as input. Write a progto iterate through the array & output words contain no match

How to.write this prog

13th Jan 2021, 10:24 AM
Ayushi Mehta
Ayushi Mehta - avatar
23 Answers
+ 26
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; int y =1; while ( count < 9) { if(words[count].Contains(letter)) { Console.WriteLine(words[count]); y += count; } count ++; } if(y == 0 || y == 1) { Console.WriteLine("No match"); } } } }
13th Jan 2021, 4:37 PM
Ayushi Mehta
Ayushi Mehta - avatar
+ 10
static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; //ваш код for (int a = 0; a < words.Length; a++) { if (words[a].Contains(letter)) { Console.WriteLine(words[a]); count++; } } if (count == 0) Console.WriteLine("No match");
19th Jun 2021, 8:23 PM
Шумилов Александр
Шумилов Александр - avatar
+ 5
Ayushi Mehta , sorry, but you gave a description to output all words that does NOT show the same as original task description.. ( found the task description). But anyway, you should now be able to fix your code. I will mark my first answer as "Not correct".
13th Jan 2021, 11:52 AM
Lothar
Lothar - avatar
+ 4
♨️♨️ , your code sample does work, but does not meet the task description from the tutorial: - if a word is matching, the output should be this word (without anything else) - if none of the words is matching, the output should be "No match" Task desription: The program you are given defines an array with 10 words and takes a letter as input. Write a program to iterate through the array and output words containing the taken letter. If there is no such word, the program should output "No match".
13th Jan 2021, 3:38 PM
Lothar
Lothar - avatar
+ 2
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; for(int i=0; i<words.Length; i++){ string theWord= words[i]; if(theWord.Contains(letter)){ Console.WriteLine(theWord); count++; } } if(count==0){ Console.WriteLine("No match"); } } } }
12th Apr 2021, 4:39 PM
Shahed Mohammad Hridoy
Shahed Mohammad Hridoy - avatar
+ 1
Ayushi Mehta , small but important changes to your code: EDITED: following code sample works fine, but does not output the expected result, as the description in original post was confusing. ... while(count<9) { if(! words[count].Contains(letter)) // "letter" was a string, but should be variable name Console.WriteLine(words[count]); // you only need to output words that does not contain the input letter, so no else is needed count ++; } ...
13th Jan 2021, 11:40 AM
Lothar
Lothar - avatar
+ 1
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; int y =1; while ( count < 9) { if(words[count].Contains(letter)) { Console.WriteLine(words[count]); y += count; } count ++; } if(y == 0 || y == 1) { Console.WriteLine("No match"); } } } }
7th Nov 2021, 11:12 PM
ANGEL ALEJANDRO MONTIEL ALONSO
ANGEL ALEJANDRO MONTIEL ALONSO - avatar
0
Sample Input : u Expected Output : fun
13th Jan 2021, 11:47 AM
Ayushi Mehta
Ayushi Mehta - avatar
0
According to your expected output your code is not correct in if condition u wrote if(words [count]. Contains ("letter")) here u need to write letter only without quotes. May be you expecting this output Simple input --enter any words which u mentioned and u have to find iteration.
13th Jan 2021, 2:39 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
//Try this one using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; while(count<10) { if(words[count].Contains(letter)) Console.WriteLine(count+"-->"+words[count]); //else // Console.WriteLine("No match"); count ++; } //your code goes here } } }
13th Jan 2021, 2:39 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Hii
15th Jan 2021, 9:59 AM
Karmveer Yadav
Karmveer Yadav - avatar
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; //your code goes here // string letter2 =""; foreach (string itemw in words) { // count = itemw.IndexOf(letter); if (itemw.Contains(letter)) { Console.WriteLine(itemw); count = 1; } } if (count == 0 ) { Console.WriteLine("No match"); } } } }
23rd Apr 2021, 5:26 AM
DINH XUAN THO
0
//using foreach loop using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; //your code goes here foreach(var item in words){ if(item.Contains(letter)){ Console.WriteLine(item); count ++; } } if(count==0) Console.WriteLine("No match"); } } }
10th Jun 2021, 6:28 PM
Zeeshan
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; bool found = false; for (count=0; count<=9; count++) { if (words[count].Contains(letter)) {found=true; Console.WriteLine(words[count]); } } if (found == false) { Console.WriteLine("No match");
13th Jun 2021, 6:31 AM
gkoutras
gkoutras - avatar
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = iConsole.ReadLine(); int count = 0; int y =1; while ( count < 9) { if(words[count].Contains(letter)) { Console.WriteLine(words[count]); y += count; } count ++; } if(y == 1) { Console.WriteLine("No match"); } } } }
30th Jun 2021, 4:49 PM
Shanmuga Priya
Shanmuga Priya - avatar
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Convert.ToString(Console.ReadLine()); int count = 0; foreach (string value in words) { if(value.Contains(letter)) { Console.WriteLine(value); count++; } }if(count==0) {Console.WriteLine ("No match");} //your code goes here } } }
13th Aug 2021, 4:38 PM
Namdar Vali
Namdar Vali - avatar
0
*************Feel free and copy pest the code and try to understand********** class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; foreach (var word in words) { if (word.Contains(letter)) { Console.WriteLine(word); } } while (true) { if (words[count].Contains(letter)) { break; } else count++; if (count == 10) { Console.WriteLine("No match"); break; } } } }
9th Sep 2021, 3:09 AM
Jobayrul Hasan
Jobayrul Hasan - avatar
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; int y =1; while ( count < 9) { if(words[count].Contains(letter)) { Console.WriteLine(words[count]); y += count; } count ++; } if(y == 0 || y == 1) { Console.WriteLine("No match"); } } } }
1st Dec 2021, 12:13 PM
Nichervan Essa Mahammad
Nichervan Essa Mahammad - avatar
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; //your code goes here foreach(var item in words){ if(item.Contains(letter)){ Console.WriteLine(item); count ++; } } if(count==0) Console.WriteLine("No match"); } }
7th Feb 2022, 6:04 PM
Mcarathy
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; foreach(var item in words){ if(item.Contains(letter)) { Console.WriteLine(item); count++; } } if(count == 0) Console.WriteLine("No match"); } } }
30th Jul 2022, 4:35 PM
Евгений
Евгений - avatar