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.

what is the way to get random from 0 - 3

+4 votes
asked Feb 2, 2023 by Benjamin Farnsworth (160 points)
rock paper scissors

2 Answers

+2 votes
answered Feb 2, 2023 by Peter Minarik (86,040 points)

In C, you generate a random number (rand()) then take the modulo 4 to have it between 0 and 3. 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    srand(time(NULL));
    printf("Random number: %d\n", rand() % 4);
    return 0;
}
0 votes
answered Feb 5, 2023 by SACHIN YADAV (260 points)
edited Feb 5, 2023 by SACHIN YADAV

First we take a variable integer and after that we provide a program to show that variable is under0-3or not

And for this we use conditional operator


#include<stdio.h>
int main ()
{
int a;
printf("enter the value of a: ");
scanf("%d",&a);
if (0<a && a<3)
printf("a is btween the range of 0-5");
else
printf("a is not between the range of 0-3");
return 0;
}
 
 

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