0

How to solve this?

How to solve this? create a Console application that allows the user to enter 10 numbers then finds the largest and smallest numbers that are not divisible by either 7 or 3. int a, n, max=0, min=0; for(n=1; n<11;n++) { Console.WriteLine("Input {0}. number: ", n); a=int.Parse(Console.ReadLine()); if(a%3!=0 && a%7!=0)&&(n==1) min=max=a; if((a%3!=0 && a%7!=0)&&(a>max)) max=a; if((a%3!=0 && a%7!=0)&&(a<min)) min=a; } Is this code good?

7th Nov 2021, 10:23 PM
dreamer
dreamer - avatar
2 Answers
+ 1
Hi dreamer There were a few issues in your code. Have a look at this adaptation of your code which will give you min and max within the range of numbers from -1000 to +1000 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sololearn { class Program { static void Main(string[] args) { int a, n, max=-1000, min=1000; for(n=1; n<11;n++){ a=int.Parse(Console.ReadLine()); if(a%3!=0 && a%7!=0){ if(a > max){ max = a; } if(a < min){ min = a; } } } Console.WriteLine("max = "+ max); Console.WriteLine("min = "+ min); } } }
7th Nov 2021, 11:12 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Rik Wittkopp thank you.
7th Nov 2021, 11:30 PM
dreamer
dreamer - avatar