+ 1

Who can write a program that from 50 (from 0 to 50) given numbers shows only numbers that divides to 3

Question

15th Sep 2020, 2:40 PM
Unknown
Unknown - avatar
13 odpowiedzi
+ 5
This can be done a little simpler in one loop, and without using an array. In the first loop, you could check if b is divisible by 3, and if so then print b. You can remove array a[] unless there is another requirement to store the values. The next tip is how to check for divisibility. One way to check is to compare floating point division against the result of integer division and see if they are the same, like if ((float)b/3.0 == b/3) //is divisible by 3, so print b Another way is to use modulo (%) to check for a remainder of zero when dividing by 3. I recommend this way, and will leave it as an exercise for you to study on your own for now.
15th Sep 2020, 5:46 PM
Brian
Brian - avatar
+ 10
Unknown , people are willing to help you, but please show us your attempt first. Put your code in playground and link it here. Thanks for your understanding!
15th Sep 2020, 4:44 PM
Lothar
Lothar - avatar
+ 4
I can. You can, too. Use a 'for' loop and check for divisibility by using the C# modulo operator, %.
15th Sep 2020, 4:12 PM
Brian
Brian - avatar
+ 4
It is useful to show what you tried, even if it won't compile or has broken logic. We'll help improve your understanding. I see that you have one public program that successfully implements a for loop. Start with that, save it as a new program, and try modifying it for this assignment. Add comments to mark where you are stuck.
15th Sep 2020, 4:52 PM
Brian
Brian - avatar
+ 4
Use a for loop x+=3 0 to 50 and return an arraylist (list in python) where (x%3==0)👍
17th Sep 2020, 10:57 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 3
probably anyone with a very basic knowledge of the if and else statement and how to divide two numbers ,I would recommend you to use Google for such basic query ,in case you get stuck you can always ask a question!
15th Sep 2020, 2:43 PM
Abhay
Abhay - avatar
+ 3
Unknown you are welcome. Glad to help.
15th Sep 2020, 6:37 PM
Brian
Brian - avatar
+ 2
Thanks Brian!
15th Sep 2020, 6:19 PM
Unknown
Unknown - avatar
+ 2
int[ ] a = new int[50]; for (int b = 0; b < 50; b+=3) { a[b] = b; } foreach (int b in a) { if(b!=0) Console.WriteLine(b); Or simply for(int b=3; b<=50; b+=3) Console.WriteLine(b); Many ways..
15th Sep 2020, 11:37 PM
Jayakrishna 🇮🇳
+ 1
I know whats Google I wrote not just to show
15th Sep 2020, 3:04 PM
Unknown
Unknown - avatar
+ 1
coffeeunderrun can you show me or Brian please don't ask my attempt I've tried
15th Sep 2020, 4:40 PM
Unknown
Unknown - avatar
15th Sep 2020, 5:07 PM
Unknown
Unknown - avatar