 How to solve the C# project multiple of 3 | Sololearn: Learn to code for FREE!

+15

# How to solve the C# project multiple of 3

How to Solve Multiple of 3 C# project Problem: 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 Multiples of 3 by "*" Sample Input 7 Sample Output 12*45*7 Q: Is it asking me to list the multiples of 3 from 1 to 7? Also, How the F*** can 7 turn into 12*45*7? They need to explain what they want.

-9

Abdul Qayom Silab🇦🇫 I just completed this assignment. you have output the numbers in a line. you need to convert every multiple of 3 into * it's not asking you to print 1 to 7 digits. you just have print 1 to N(where n is the user inputting any number)

+57

this is for everyone who is confused about how in the sample problem its input is 7 and the output includes 12 and 45 (which is obviously not between 1-7). In your program, it will not include the spaces in between the numbers. So, it isn't printing 12 and 45. It's printing 1, 2, 4, 5, 7 as numbers that are not multiples of 3 from 1-7. replacing the multiples of 3 from 1-7 with * (which are 3 and 6). That makes the output 12*45*7.

+28

using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for(int i=1; i<=number; i++) { if(i % 3==0) { Console.WriteLine("*"); } else { Console.WriteLine(i); } } } } }

+18

int number = Convert.ToInt32(Console.ReadLine()); for (int i=1;i<=number;i++) if (i%3==0) {Console.WriteLine("*"); } else { Console.WriteLine(i);}

+14

Can someone tell me where the 12 and 45 are coming from

+13

(for i = 1; i <= number; i++) if (i%3 == 0) Print "*" else print i; Note: this is just the pseudo code not the real program, hope it helps

+5

i feel like this challenge is way out of line for the level of knowledge gained so far for a person new to coding. as someone new to this stuff, ive been working through this course, and up until this point, ive been able to figure out pretty much everything under my own steam. this challenge however, id have never in a hundred years been able to figure out without the use of a google search. the question is badly phrased, and even after seeing the solution, its still breaking my brain to figure it out.

+4

Dude is really confusing 12 is twelve its 1 and 2 putting together, so it's using Write instead of WriteLine... So its 1 2 * 4 5 * 7

+3

use Console.Write(); instead of : Console.WriteLine(); in order to align the output in one line ... Good Luck . //your code goes here for (int i = 1; i <= number; i++) { if (i % 3 == 0) { Console.Write("*"); } else { Console.Write(i); } }

+2

using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for(int i=1; i<=number; i++) { if(i % 3==0) { Console.WriteLine("*"); } else { Console.WriteLine(i); } } } } } Urraaaaaa!!!!!

+2

Don't use Console.WriteLine since you want it on the same line instead use Console.Write int number = Convert.ToInt32(Console.ReadLine()); for(int x = 1; x <= number; x++) if (x % 3 == 0) { Console.Write("*"); } else { Console.Write(x); }

+1

startNumber++ in the loop, <= condition. also handle what you should print if the condition is not true. use Write() to print in a single line without going to next line after printing MrDevEzeoke

+1

it was cofusing that SL didn't clarified the type of output data. Outputs can be ints and * char line by line in console, no need to convert all in one line string.

+1

Ugh. This is so confusing when you look at it at face value. Count from 1 to the Input number. Maybe write it down on a notebook. Then compare the numbers you wrote to what the output is asking. Look for similarities. It's obnoxiously simple of an answer. If you still don't get it, pretend the asterisk is a censor.

+1

int i; Console.WriteLine(“Enter a number=“); int number = Convert.ToInt32(Console.ReadLine()); for(i=1;i<=number;i++){ if(i%3==0) Console.Write(“*”); else Console.Write(i); }

+1

using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); for(int i=1;i<=number;i++){ Console.Write((i%3==0)?"*":Convert.ToString(i)); } } } }

0

i did’t understand on theory of this program please send me the code i will try to understand

0

loop, check condition, print value. use Write(). pretty simple.

0

Idk but I tried this: for(int startNumber = 1; startNumber < number; number++){ Console.WriteLine(number); if(number % 3 == 0){ Console.WriteLine("*"); } } but...... its not working. Its going from 7 to 1000 or something. Any suggestions or changes to make?

0

Your right! Damm. Thank you Flash