0
How to make this in C#
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
12 Answers
+ 2
TheMasterBee
Why there is x = 9 and x < 19?
Number start from 1 so there should be x = 1
And you have to take input so your loop should be like :
while (x <= input) {
x++;
}
Print * when x % 3 == 0 otherwise print x
+ 1
TheMasterBee
x should be initialise with 1 and semicolon missing
+ 1
First you need to understand the question properly otherwise you could not able to solve this question
Suppose you enter 7
Now it will return 12*45*7
Here 'star' present in place of 3,6 as they are multiple of 3.
Here just using a for loop with a condition
for(int i=1;i<input+1;i++)
{
if(i%3==0)
{
Console.Write("*")
}
Console.Write(i)
}
0
You create a loop from 1 to N including. Then you use the remainder operator to check if the numbers are multiples of 3.
0
Can you write??
0
First, you should make an attempt by yourself, and then we can correct you if your code doesn't work as expected.
0
Ok fine
0
class Program
{
static void Main(string[] args)
{
int number = Convert.ToInt32(Console.ReadLine());
int x = 1;
while (x<=number)
{
if (x%3!=0)
Console.Write(x);
else
Console.Write("*");
x++;
}
}
}
0
Is here a problem?!!
0
Yes thank you!!
0
It is that