Multiples of 3 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Multiples of 3

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 I don't need the code I just don't under stand what its asking and what I am supposed to do. Also where did the 12 and 45 come from

3rd Jan 2021, 1:51 AM
Abner Koffi
8 Answers
- 3
Never mind, I realized that it was counting the numbers 1, 2, skipped 3, counted 4, and then 5
3rd Jan 2021, 2:00 AM
Abner Koffi
+ 7
Well. you're correct! they simply replaced 3 with * you also gonna need Console.write(); to print the numbers on the same line.
3rd Jan 2021, 3:29 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 3
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); for (int i=1;i<=number;i++) if (i%3==0) {Console.WriteLine("*"); } else { Console.WriteLine(i);} } } }
19th Apr 2021, 2:36 AM
Xar Hang
Xar Hang - avatar
+ 2
Don't give up Aleksei Gorlanov
28th Mar 2021, 5:33 PM
DOOM
DOOM - avatar
+ 1
This code outputs exactly what is asked by the problem but is not passing all the tests. using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { // transform to integer int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for(int i = 1; i < number; i++){ if(i % 3 == 0){ Console.WriteLine("*"); }else{ Console.WriteLine(i); } } Console.WriteLine(number); } }
7th Mar 2021, 8:18 PM
Elias Prado
Elias Prado - avatar
0
i’ve done 3 free test, but it shows that i have mistake in pro tests. don’t know what to do
10th Jan 2021, 5:45 PM
Aleksei Gorlanov
Aleksei Gorlanov - avatar
0
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); for(int i =1;i<=number;i++) { string j = i.ToString(); j = (i%3==0)? "*" : j ; Console.Write(j); } } } }
7th Nov 2021, 12:56 PM
Hoosam Meray
Hoosam Meray - avatar
0
@Elias Prado I wrote exactly your code and the tests pass, but I get an error message that the code is wrong. This is the code I wrote: namespace test3 { class Program { static void Main(string[] args) { int num = Convert.ToInt32(Console.ReadLine()); for (int x = 1; x < num ; x++) { if (x % 3 == 0) { Console.Write('*'); }else Console.Write(x); } Console.Write(num); } } }
8th Nov 2021, 3:50 PM
vectorcannon66