May 7, 2012

C Program to toss a coin using random function.

Write a c program to toss a coin using random function.
In this Program,We use the rand()%2 function that will compute random integers 0 or 1.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

* You can use all the programs on
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact
* To find more C programs, do visit
* and browse!
*                      Happy Coding

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

int main(void) {
    int toss = 0;
    int call = 0;
    toss = rand() % 2;
    printf("Say head or tail! press 0 for head and 1 for tail:\n\n");
    scanf("%d", &call);
    if(call==0 || call==1)
        if(toss == call)
            printf("You called it correctly ... it is tail\n");
            printf("You called it correctly ... it is head\n");
            printf("No way is head !\n");
            printf("No way ... it is tail!\n");
    printf("Invalid call!!!!!\n\n");
    return 0;
Read more Similar C Programs
Learn C Programming
Number System
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link