SET OF PROGRAMS

This blog provided "C" programs for beginners. Providing c programs for students.enjoy this blog.this blog include many c programs for engineering students, IT engineering students and programmers this blog is very useful.this blog post daily 1-5 programs for you.this programs use full for devlop games devlops application and much more. This blog programs useful for projects because all programs post with explanations.

Search Bar

Ads Here

Sunday, 24 June 2018

C program for guess the toss of coin

GUESS THE TOSS OF A COIN

This program very useful to guess toss this program take randomly answers HEAD OR TAILS . We use to this program for college project.


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
 main ()
 {
 int number,guess;
 srand ( time(NULL) );
 //To get numbers between 0 and 1
 number = rand() % 2;
 printf("Guess 1 for tail or 0 for head\n");
 scanf("%d",&guess);
 printf("Result of toss is\n");
 if(number==0)
 {
  printf("Head\n");
 }
 else
 {
  printf("Tail\n");
 }
 printf("You guessed\n");
 if(guess==0)
 {
  printf("Head\n");
 }
 else
 {
  printf("Tail\n");
 }
 if(number==guess)
 {
      printf("Hurray! You won the toss\n");
 }
 else
 {
  printf("Oops! Better Luck Next Time\n");
 }
 }
Output:
Guess 1 for tail or 0 for head
0
Result of toss is
Tail
You guessed
Head
Oops! Better Luck Next Time

Explanation:
//Coming Soon..

No comments:

Post a Comment