0
Help please
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
5 Answers
+ 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
+ 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() ;
0
But how do you make it go in a single line?
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
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.