+ 1

Logic question in C#

I am doing a challenge question. Without giving me the code, please explain to me what they are asking me for here logically. I am trying to understand where they are getting 12 and 45 from, out of an input of 7. I thought we are trying to get all numbers between 1 and input (in this case 7), replacing the ones that are multiples of 3 by *. Am I just not grasping the math? If I understand the math behind it, I will know how to code it. Please help. Question below: 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

16th Aug 2022, 3:11 PM
Lisa Kinoti
Lisa Kinoti - avatar
15 odpowiedzi
+ 3
N= 7 -> 1 2 * 4 5 * 7 N = 9 -> 1 2 * 4 5 * 7 8 * and etc.
16th Aug 2022, 3:33 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 7
How many attempts did you made? see sololearn is a learning site so you should first try it yourself number of times the below is the gist hope it helps int number = Convert.ToInt32(Console.ReadLine()); for(int i = 1; i<= number; i++){ if(i%3 ==0) { Console.Write("*"); } else { Console.Write(i); }
16th Aug 2022, 3:21 PM
Suparna Das
Suparna Das - avatar
+ 7
Lisa Kinoti have you understood the logic I can see that you tried so keep going And for the next projects try not to ask in the Q&A section without trying yourself first Happy Sololearning
16th Aug 2022, 3:36 PM
Suparna Das
Suparna Das - avatar
+ 6
Yaroslav Vernigora I read the question that's why I asked her whether she tried or not And so I gave just gave a gist By the way thanks for your reply
16th Aug 2022, 3:25 PM
Suparna Das
Suparna Das - avatar
+ 6
Lisa Kinoti 👍🏻👌🏻
16th Aug 2022, 3:42 PM
Suparna Das
Suparna Das - avatar
+ 5
Yaroslav Vernigora 👍🏻👌🏻
16th Aug 2022, 3:32 PM
Suparna Das
Suparna Das - avatar
+ 2
yes, N is an input number. it can be any: 6 or 9 or 32. your task was to derive a sequence of numbers from one to that number, but instead of numbers multiples of 3 to derive *
16th Aug 2022, 3:31 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Suparna Das you read the question inattentively
16th Aug 2022, 3:23 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Suparna Das, wow. It looks like maybe I am complicating the problem. Thanks. Let me try this.
16th Aug 2022, 3:24 PM
Lisa Kinoti
Lisa Kinoti - avatar
+ 1
Suparna Das, it worked! Studying the code and Somya's explanation to see what I wasn't understanding.
16th Aug 2022, 3:29 PM
Lisa Kinoti
Lisa Kinoti - avatar
+ 1
Yaroslav Vernigora, thank you so much. I was reading the output wrong and was trying to code according to what I was seeing. See my explanation to Suparna above. Lesson learned. In the future, I will just trust myself and code it how I understand it and see if the results match.
16th Aug 2022, 3:42 PM
Lisa Kinoti
Lisa Kinoti - avatar
+ 1
int i =1; while( i <=number){ if(i%3==0){ Console.Write("*"); } else{ Console.Write(i); } i++; } I think, this will help.
18th Aug 2022, 6:29 AM
Jay Mukherjee
Jay Mukherjee - avatar
0
Yaroslav Vernigora, Hi :) I have been reading the question for a day now and can't figure out where some of these numbers in the output are coming from. Where am I going wrong. Is N not the input, e.g 7 in this case?
16th Aug 2022, 3:26 PM
Lisa Kinoti
Lisa Kinoti - avatar
0
Suparna Das, I have been trying since yesterday like 20 times. That's why I came here to see where am going wrong. I was looking at the question as though I should print all numbers between 1 and the input number, replacing the ones that are multiples of 3 with *. So, in my mind, with input of 7, I was thinking it would be 1,2,*,4,5,*,7. Instead I was seeing 12,*,45,*,7... lol. And I was like, where the heck are they getting 12 and 45 from? And I was confused how to code logic I didn't understand.. Ah, so silly.. I see now. They should have given the output example with the numbers either separated by comas or on top of each other like it shows on results. Joining them together like that confused me and made me think I was dumb.. haha. Anyways, thanks guys.
16th Aug 2022, 3:34 PM
Lisa Kinoti
Lisa Kinoti - avatar