0

In c programming I don't understand the code can anyone explain

#include<stdio.h> #include<stdlib.h> #include<time.h> int main(){ int number, guess, nguesses=1; srand(time(0)); number = rand()%100 + 1; // Generates a random number between 1 and 100 // printf("The number is %d\n", number); // Keep running the loop until the number is guessed do{ printf("Guess the number between 1 to 100\n"); scanf("%d", &guess); if(guess>number){ printf("Lower number please!\n"); } else if(guess<number){ printf("Higher number please!\n"); } else{ printf("You guessed it in %d attempts\n", nguesses); } nguesses++; }while(guess!=number); return 0; }

5th Sep 2021, 5:58 AM
Abhishek Bairwa
Abhishek Bairwa - avatar
5 odpowiedzi
+ 1
In simple words rand function will generate different different random numbers between 0 to 100 then u have to enter one number If your entered number is greater then generated one then first if case will execute Same if number is greater than guessing number then second if will work otherwise else statement will execute. And ngusses will increase every time if while condition will True this is working as a counter .it will be stop when Condition will be false means guessing number will be equal to entered number.
5th Sep 2021, 6:12 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Sir I don't know about stand(time(0)) What is this
5th Sep 2021, 6:53 AM
Abhishek Bairwa
Abhishek Bairwa - avatar
0
Srand
5th Sep 2021, 6:58 AM
Abhishek Bairwa
Abhishek Bairwa - avatar