+ 1
Who can write a program that from 50 (from 0 to 50) given numbers shows only numbers that divides to 3
Question
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.
+ 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!
+ 4
I can. You can, too. Use a 'for' loop and check for divisibility by using the C# modulo operator, %.
+ 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.
+ 4
Use a for loop x+=3 0 to 50 and return an arraylist (list in python) where (x%3==0)👍
+ 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!
+ 3
Unknown you are welcome. Glad to help.
+ 2
Thanks Brian!
+ 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..
+ 1
I know whats Google I wrote not just to show
+ 1
coffeeunderrun can you show me or Brian please don't ask my attempt I've tried
+ 1
https://code.sololearn.com/cUi87un1e2U0/?ref=app
Here's my code