Answer to Question #248226 in C# for Holik

Question #248226
A four-digit number is given. Find the number 3 in it.
1
Expert's answer
2021-10-07T23:38:53-0400
using System;
using System.Collections.Generic;


class Program {
    static void Main(string[] args) {
		int number = Convert.ToInt32(Console.ReadLine());
		var result = find3InNumber(number);
		Console.WriteLine("Digit '3' indexes:");
		Console.WriteLine("[{0}]", string.Join(", ", result));
    }


	private static int[] find3InNumber(int number){
		return findCharInString('3',number.ToString());
	}


	private static int[] findCharInString(char dig,string str){
		var places = new List<int>(4);
		
		for(int i = 0;i < str.Length; i++){
			if (dig == str[i])
				places.Add(i);
		}


		return places.ToArray();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS