
Concept explainers
4) Write a C program to input a random number in the range [1,10] and also input numbers from the user until the user entered number matches with the random number generated. In the output, print the number of guesses in which the user input matches with the entered number.

here we write code in c:
==============================================================================
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
int mynumber,usernumber;
int count=1;
srand(time(NULL));
mynumber = (rand()%10 +1);
printf("enter any number between 1 to 10:\n");
while(1){
printf("enter your guess:\n");
scanf("%d",&usernumber);
if(mynumber == usernumber){
printf(" total guesses count:%d",count);
break;
}
else {
count++;
printf("try again.\n");
}
}
return 0;
}
Step by stepSolved in 2 steps with 1 images

- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





