Any idea on how to solve this? [SOLVED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Any idea on how to solve this? [SOLVED]

You are an elementary school teacher and explaining multiplication to students. You are going to use multiplication by 3 as your example. The program you are given takes N number as input. Write a program to output all numbers from 1 to N, replacing all numbers that are multiples of 3 by "*". Sample Input 7 Sample Output 12*45*7 My attempt: using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); int x = 1; //your code goes here while(x<=N){ if (N%3==0){ Console.Write("*"); } Console.Write("{0}", x++); } } } }

17th Nov 2021, 11:08 PM
Master Chief
Master Chief - avatar
5 Answers
+ 3
Professor Albus x = 1 Then how while(x < 1) would be true?
17th Nov 2021, 11:11 PM
A͢J
A͢J - avatar
+ 3
Professor Albus Now ok but there should be x <= N (x % 3 == 0) Console.Write("*"); else Console.Write(x); x++;
17th Nov 2021, 11:15 PM
A͢J
A͢J - avatar
+ 1
Professor Albus Well done but bad practice to write same logic in both if else condition like x++ You can write only once after the else condition but outside the else like: if (x % 3 == 0) { // print } else { //print } x++;
18th Nov 2021, 12:21 AM
A͢J
A͢J - avatar
17th Nov 2021, 11:13 PM
Master Chief
Master Chief - avatar