How to solve the Module 2 "Multiple of 3" problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to solve the Module 2 "Multiple of 3" problem

I tried it for hours, and i just can't do it. Pls can someone post the code in the comments? Thx. Problem: 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 //the numbers are separated, but it returns them toghether

7th Jan 2021, 3:56 PM
Samu Sacomi
Samu Sacomi - avatar
10 Answers
+ 1
Samu Sacomi for(x=0;x<number;x++) { if(x%3==0) { Console.WriteLine("*"); }
7th Jan 2021, 6:56 PM
Abhay
Abhay - avatar
+ 4
well. your code? so we can find what you were doing wrong and give the solution
7th Jan 2021, 4:01 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 3
Samu Sacomi I haven't seen anything like this in a for loop => for(! (number=x) ? x++ : break ); Anyway that statement is giving me error
7th Jan 2021, 5:03 PM
Abhay
Abhay - avatar
+ 2
int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for(int x = 1; x <= number; x++) { if(x % 3 == 0) { Console.WriteLine("*"); } else { Console.WriteLine(x); } }
10th Aug 2021, 11:55 AM
Rakesh Ranjan
Rakesh Ranjan - avatar
+ 1
Ok can you place a link to the code you have attempted so far? Or copy paste the code if you can't find the link
7th Jan 2021, 4:01 PM
Abhay
Abhay - avatar
+ 1
Ok thanks a lot!!
7th Jan 2021, 7:14 PM
Samu Sacomi
Samu Sacomi - avatar
+ 1
:)
28th Oct 2022, 11:23 AM
Süleyman Özdemir
Süleyman Özdemir - avatar
0
Maybe, I don't know what I'm supposed to use in this problem
7th Jan 2021, 5:42 PM
Samu Sacomi
Samu Sacomi - avatar
0
Im using if -else😂😂
19th May 2021, 9:19 AM
Kazkay 'a
Kazkay 'a - avatar
- 1
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); //your code goes here int x = 0; for(! (number=x) ? x++ : break ); { if(number%3==0) { Console.WriteLine(*); } else { Console.WriteLine(x); } } } } } }
7th Jan 2021, 4:57 PM
Samu Sacomi
Samu Sacomi - avatar