+ 1
How to solve the Module 2 "Multiple of 3" problem
I tried it for hours, and i just can't do it. Pls can someone post the code in the comments? Thx. 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 are multiples of 3 by "*". Sample Input: 7 Sample output: 12*45*7 //the numbers are separated, but it returns them toghether
10 Answers
+ 1
Samu Sacomi
for(x=0;x<number;x++)
{
if(x%3==0)
{
Console.WriteLine("*");
}
+ 4
well. your code? so we can find what you were doing wrong and give the solution
+ 3
Samu Sacomi I haven't seen anything like this in a for loop => for(! (number=x) ? x++ : break );
Anyway that statement is giving me error
+ 2
int number = Convert.ToInt32(Console.ReadLine());
//your code goes here
for(int x = 1; x <= number; x++)
{
if(x % 3 == 0)
{
Console.WriteLine("*");
}
else
{
Console.WriteLine(x);
}
}
+ 1
Ok can you place a link to the code you have attempted so far? Or copy paste the code if you can't find the link
+ 1
Ok thanks a lot!!
+ 1
:)
0
Maybe, I don't know what I'm supposed to use in this problem
0
Im using if -elseđđ
- 1
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
int x = 0;
for(! (number=x) ? x++ : break );
{
if(number%3==0)
{
Console.WriteLine(*);
}
else {
Console.WriteLine(x);
}
}
}
}
}
}