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

1st Jan 2021, 12:09 PM
Mani Pakravanan
Mani Pakravanan - avatar
9 Respostas
+ 8
As I Am AJ ! mentiined, a for loop should be preferred. This code has a better readability compared to the while loop.
1st Jan 2021, 1:28 PM
Lothar
Lothar - avatar
+ 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); } } } }
1st Jan 2021, 12:40 PM
A͢J
A͢J - avatar
+ 5
Mani Pakravanan Show your code.
1st Jan 2021, 12:21 PM
A͢J
A͢J - avatar
+ 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++; } } } }
1st Jan 2021, 12:38 PM
A͢J
A͢J - avatar
+ 2
Mani Pakravanan Replace the number which is multiple of 3. You can use modulus operator % to check.
1st Jan 2021, 12:12 PM
A͢J
A͢J - avatar
+ 2
thanks I Am AJ !
1st Jan 2021, 12:50 PM
Mani Pakravanan
Mani Pakravanan - avatar
+ 1
I Am AJ ! i cant get what the question wants i used do while and while loops but it doesnt works!
1st Jan 2021, 12:17 PM
Mani Pakravanan
Mani Pakravanan - avatar
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 }} } }
1st Jan 2021, 12:31 PM
Mani Pakravanan
Mani Pakravanan - avatar
0
for (int i=1; i<=number; i++){ if(i%3 != 0) Console.Write(i); else Console.Write("*"); }
4th Nov 2021, 7:05 PM
Demondotcom
Demondotcom - avatar