mardi 16 novembre 2021

How can I substract random no from 100 to 0 by another random no 1-10 and print subtraction no in c#?

so basically I have 100-0 no and 1-10 no. now i have to go from 100 to 0 by substracting random no by 1-10 and print those subtraction no. I have used for loop to solve this problem. but this problem have to solve without decrement just randomly. here is my code.

for(int i = 100; i >=0; i--) {
            Random ran = new Random();
            int randomNum = ran.Next(1, 10);
            int val = i - randomNum;
            if (val >= 0)
            {
                Console.WriteLine(val);
                i--;
            }
        }

can anyone help me?




Aucun commentaire:

Enregistrer un commentaire