I want your help with this question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want your help with this question

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 N number is multiple of 3 if (N%3 == 0)

17th Feb 2023, 11:27 AM
BINIAM EPHREM
2 Answers
+ 5
VSYZ It is not really helpful to give them the exact answer. It is usually best to ask them for their attempt and then help them debug what they already have.
17th Feb 2023, 3:33 PM
Justice
Justice - avatar
+ 1
using System; class Program { static void Main(string[] args) { Console.Write("Enter N: "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { if (i % 3 == 0) { Console.Write("*"); } else { Console.Write(i); } } Console.WriteLine(); } } 1. It prompts the user to enter a value for N. 2. It reads the input as an integer and stores it in the n variable. 3. It uses a for loop to iterate from 1 to n. 4. For each number i in the loop, it checks if i is a multiple of 3 using the modulo operator %. 5. If i is a multiple of 3, it outputs a "*" character instead of the number. 6. If i is not a multiple of 3, it outputs the number. 7. After the loop is done, it outputs a newline character to move the cursor to the next line.
17th Feb 2023, 11:38 AM
VSYZ
VSYZ - avatar