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

23rd Aug 2022, 1:58 PM
TheMasterBee
TheMasterBee - avatar
12 Respuestas
+ 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
23rd Aug 2022, 3:45 PM
A͢J
A͢J - avatar
+ 1
TheMasterBee x should be initialise with 1 and semicolon missing
23rd Aug 2022, 4:10 PM
A͢J
A͢J - avatar
+ 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) }
25th Aug 2022, 1:38 AM
Bapon Kar
Bapon Kar - avatar
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.
23rd Aug 2022, 3:02 PM
Jan
Jan - avatar
0
Can you write??
23rd Aug 2022, 3:05 PM
TheMasterBee
TheMasterBee - avatar
0
First, you should make an attempt by yourself, and then we can correct you if your code doesn't work as expected.
23rd Aug 2022, 3:14 PM
Jan
Jan - avatar
0
Ok fine
23rd Aug 2022, 3:15 PM
TheMasterBee
TheMasterBee - avatar
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++; } } }
23rd Aug 2022, 4:08 PM
TheMasterBee
TheMasterBee - avatar
0
Is here a problem?!!
23rd Aug 2022, 4:08 PM
TheMasterBee
TheMasterBee - avatar
0
Yes thank you!!
23rd Aug 2022, 4:20 PM
TheMasterBee
TheMasterBee - avatar
0
It is that
23rd Aug 2022, 4:20 PM
TheMasterBee
TheMasterBee - avatar