 Logic question in C# | Sololearn: Learn to code for FREE!

+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

+2

N= 7 -> 1 2 * 4 5 * 7 N = 9 -> 1 2 * 4 5 * 7 8 * and etc.

+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); }

+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

+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

+6

+5

Yaroslav Vernigora 👍🏻👌🏻

+3

To get multiple of 3 use modulo operator Iterate the number from 1 to input number Check the input number is multiple of 3 if yes then replace that number with "*" For example: if number%3 == 0 Then replace that number with start ( * ) mark

+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 *

+1

Suparna Das you read the question inattentively

+1

Suparna Das, wow. It looks like maybe I am complicating the problem. Thanks. Let me try this.

+1

Suparna Das, it worked! Studying the code and Somya's explanation to see what I wasn't understanding.

+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.

+1

int i =1; while( i <=number){ if(i%3==0){ Console.Write("*"); } else{ Console.Write(i); } i++; } I think, this will help.

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?

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.