From b314f2f427b0c8cc24fa551081bfc8e36f49b605 Mon Sep 17 00:00:00 2001 From: Prashantsetia <66926991+Prashantsetia@users.noreply.github.com> Date: Sat, 2 Oct 2021 02:48:02 +0530 Subject: [PATCH] Random Number Game Program In C --- random_game.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 random_game.c diff --git a/random_game.c b/random_game.c new file mode 100644 index 0000000..a0dfe39 --- /dev/null +++ b/random_game.c @@ -0,0 +1,38 @@ +#include +#include +#include + + +int main(){ + + int n , attempts = 1; + char str[20]; + srand(time(NULL)); + + int num = rand(); + + int rand_num = num % 100 + 1; + printf("Random No. is : %d",rand_num); + + printf("\nEnter Your Name : "); + scanf("%s",&str); + do{ + + printf("\nEnter the no : "); + scanf("%d",&n); + + if(nrand_num){ + printf("\ntry lower no."); + } + else + { + printf("\nCongratulations !!! %s, You got this in %d attempts",str,attempts); + } + + attempts++; + + }while(n != rand_num); +} \ No newline at end of file