0
please can anyone give me a tip on multiple of 3 c#
i am stuck in multiple of 3 c#. if anyone can help me please just give me a tip
9 Answers
+ 8
As I Am AJ ! mentiined, a for loop should be preferred. This code has a better readability compared to the while loop.
+ 7
Mani Pakravanan
Or you can try for loop
using System;
using System.Collections.Generic;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
for(int i = 1; i <= num; i++) {
if (i % 3 == 0)
Console.Write("*");
else
Console.Write(i);
}
}
}
}
+ 5
Mani Pakravanan Show your code.
+ 4
Mani Pakravanan
using System;
using System.Collections.Generic;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
int i = 1;
while(num > 0) {
if (num % 3 == 0)
Console.Write("*");
else
Console.Write(i);
num--;
i++;
}
}
}
}
+ 2
Mani Pakravanan Replace the number which is multiple of 3. You can use modulus operator % to check.
+ 2
thanks I Am AJ !
+ 1
I Am AJ ! i cant get what the question wants i used do while and while loops but it doesnt works!
0
using System;
using System.Collections.Generic;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("");
int num = Convert.ToInt32(Console.ReadLine());
while(num%3 == 0);
{
Console.WriteLine(num + "*" + num);
num++;
//your code goes here
}}
}
}
0
for (int i=1; i<=number; i++){
if(i%3 != 0) Console.Write(i);
else Console.Write("*");
}