0

Could someone help me with this: 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

7th Feb 2022, 7:03 PM
Andrius Savčiukas
+ 2
Please link your code so we can help you. You can approach the task like this * use a loop * on each iteration check if the current number is divisible by 3 using the modulo operator % * if it is, print *, else print the number
7th Feb 2022, 7:08 PM
Lisa + 1
Andrius Savčiukas What is the print statement you are using.. ? WriteLine() adds a new line while if you don't need to add line break use Write() method. use Console.Write() ;
7th Feb 2022, 8:01 PM
Jayakrishna 🇮🇳
0
But how do you make it go in a single line?
7th Feb 2022, 7:21 PM
Andrius Savčiukas
0
static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for(int N = 0;N%3==0;N++){ Console.Write("*"); continue; } Console.Write(number); This is the closest I got, but it’s not even close :D
8th Feb 2022, 1:23 PM
Andrius Savčiukas
0
static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for(int N = 1;N<number;N++){ //check condition to stop loop is N<number //use a if block to check divisable by 3, and print * //else block prints number if (N%3==0) Console.Write("*"); else Console.Write(N); } Console.Write(number); //final number, you can also use N<=number and remove this print } //Andrius Savčiukas read comments to understand code changes. //hope this helps.
8th Feb 2022, 1:45 PM
Jayakrishna 🇮🇳