Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

write a program that generated any random numbers to the screen

0 votes
asked Apr 4, 2019 by aklilu (120 points)

3 Answers

0 votes
answered Apr 4, 2019 by Alexandru Pricop (140 points)
#include <iostream>
#include <stdlib.h>

using namespace std;

void generator1(int c)
{
    int randNum;
    
    randNum = rand() % c + 1;
    cout << "Random number generated between 0 and " << c << " is : " << randNum << endl;
}

void generator2(int min, int max)
{
    int randNum;
    randNum = rand()%(max-min + 1) + min;
    
    cout << "Random number in between " << min << " and " << max << " is : " << randNum << endl;
}

void generate()
{
    // Generate a number from 0 to a const
    
    int x;
    
    cout << "Generate an int number from 0 to x. Introduce x" << endl;
    cin >> x;
    
    generator1(x);
    cout << endl;
    
    // Generate a random number in a certain range
    
    int min , max;
    
    cout << "Generate an int number from value 'min' to value 'max'" << endl;
    cout << "min = " << flush;
    cin >> min;
    
    cout << "max = " << flush;
    cin >> max;
    
    generator2(min,max);
    cout << endl;
}

int main(void)
{
    generate();
    
    return 0;
}
0 votes
answered Apr 12, 2019 by anonymous
#include<stdio.h>

#include<conio.h>

void main()

{

int i,j;

for(i=1;i<=10;i++)

{

for(j=1;j<=10;j+++)

{

printf("%12d",i*j);

}

printf("\n");

}

getch();

}
0 votes
answered Jun 10, 2019 by Satya Thorati (150 points)
# In Python
# Random OTP generation using Scripting Approach

import random

print("Scripting Approach ..... ")

print(random.randint(0, 9), random.randint(0, 9), random.randint(0, 9), random.randint(0, 9), random.randint(0, 9), random.randint(0, 9))

# Functional approach


def random_number():

    return print(random.randint(0, 9), random.randint(0, 9), random.randint(0, 9), random.randint(0, 9))


print("Functional Approach ..... ")
random_number()
random_number()
random_number()


# OOP Approach


class Test:
    def random_number(self):
        return print(random.randint(0, 9), random.randint(0, 9), random.randint(0, 9), random.randint(0, 9))

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...