কম্পিউটার

এন ডাইস রোলার অনুকরণ করতে C++ প্রোগ্রাম


এখানে N ডাইস রোলার অনুকরণ করার কোড আছে। এটি 1-6 এর মধ্যে এলোমেলো সংখ্যা তৈরি করে করা যেতে পারে।

অ্যালগরিদম

Begin
   Declare n
   Read n
   For i = 0 to n-1 do
      Generate sequence with rand() mod 6 + 1
      Print the sequence
   Done
End

উদাহরণ কোড

#include <iostream>
using namespace std;
int main(int argc, char **argv) {
   cout << "Enter the number of dice: ";
   int n;
   cin >> n;
   cout << "The values on dice are: ";
   for (int i = 0; i < n; i++)
      cout << (rand() % 6) + 1<<" ";
}

আউটপুট

Enter the number of dice: The values on dice are: 2 5 4 2 6 2 5

  1. C++ প্রোগ্রামে বাইনারি অনুসন্ধান?

  2. GCD খুঁজে পেতে C++ প্রোগ্রাম

  3. C++ হ্যালো, বিশ্ব! কার্যক্রম

  4. C++ প্রোগ্রাম স্ট্রাকচার