Question

Write a program that finds how many times a prime number is obtained when a dice is tossed 100 times.

programming language must be in BASIC

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h>
int main()
{
    int i,j,val,f=0,count=0,temp;
    int min=1,max=6;
    for(i=0;i<100;i++)
    {
        printf("\n\nThe dice is rolled %d times",i+1);
        val=(rand() % (max - min + 1)) + min;
        if(val!=1)
        {    
            
            for(j=1;j<=val;j++)
            {
                if(val%j==0)
                    f++;
            }
            if(f==2)
            {
                printf("\nWe got a prime number: %d",val);
                count++;
            }
            else
                printf("\nWe didn't get a prime number this time");
           
        }
        else
            printf("\nWe got %d which neither prime nor composite",val);
        f=0;
        val=0;
    }
    printf("\n\n---------->We got %d prime numbers<----------",count);
}

I have used C programming here, which is a high level programming language and it is a very BASIC language for the beginners

Add a comment
Know the answer?
Add Answer to:
programming language must be in BASIC Write a program that finds how many times a prime...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT