Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with these two problems. For the second problem, I posted the code b

ID: 3796624 • Letter: I

Question

I need help with these two problems. For the second problem, I posted the code below that is mentioned to be in "Lab 4", however, it needs to be adjusted.

Language in C...not C++.

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

int main(void) {

int n = 1000;

//seed the random number generator
srand(time(NULL));
int number = (rand() % n) + 1;   // secret number

int guess = -10;                  
int num_guesses = 0;

printf("Guess-A-Number Game! ");
printf("Enter a number between 1 and %d ", n);
scanf("%d", &guess);
  
num_guesses = num_guesses + 1; // alternative: num_guesses++
  
//TODO: place your code here
  
while(guess != number) {
   if(guess > number) {
       printf("%d is too high ", guess);
   }
   else {
       printf("%d is too low ", guess);
   }

// Repeat by asking for another guess
printf("Enter another guess: ");
scanf("%d", &guess);
  
num_guesses = num_guesses + 1;
}
  
printf("Congratulations, you found it! Number of guesses: %d ", num_guesses);
  
return 0;
}

2. Fibonacci (fib.c) In Mathematics, Fibonacci sequence is defined by the set of integers characterized by the fact that every number after the first two is the sum of the two preceding ones. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. The first few numbers in this sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 Write a program that prompts the user to enter a number and then calculate the Fibonacci sequence up to that position. After the first two numbers the third and all following numbers are the sum of the previous two numbers. The part that calculates the sequence should be in its own self contained function separate from the main function, and you are encouraged to make this function as independent as possible because it might be re-visited in a later assignment. Implement this function void fact (int n) Number of terms 10 0 1 1 2 3 5 8 13 21 34 3. Guessing Game (guess.c) Write a program similar to the one in Lab 4 over loops that prompts a user for a number and then tells them if they are too high or too low. Instead of using a while loop as in the lab you will use a for loop and allow for a fixed number of entries. If an invalid number a number not in the range 1-10) is entered you will ignore it and decrease the loop counter as if that entry never happened. Set the random number to be between 1 and 10 and the loop to go 10 times. Implement this function: int check in n, int number)

Explanation / Answer

2)program:-
#include<stdio.h>
void main()
{
int number;
printf("Enter Number of terms :");
scanf("%d",&number);
printf(" the sequence is : 0 1 ");
fact(number);
}
void fact(int n)
{
int i;
int f1=0,f2=1,f3;
for(i=2;i<n;i++)
{
  f3=f2+f1;
  printf("%d ",f3);
  f1=f2;
  f2=f3;
}
}

Output:-
i)
Enter Number of terms :5

the sequence is : 0 1 1 2 3

Process exited with return value 5
Press any key to continue . . .

ii)
Enter Number of terms :15

the sequence is : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Process exited with return value 15
Press any key to continue . . .

3) program:-

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int num_guesses=0;
int guess = -10;
int main(void)
{
int n = 10,t;
//seed the random number generator
srand(time(NULL));
int number = (rand() % n) + 1;    // secret number
printf("Guess-A-Number Game! ");
printf("Enter a number between 1 and %d ", n);
scanf("%d", &guess);
num_guesses = num_guesses + 1; // alternative: num_guesses++
t=check(guess,number);
if(t>0&&t<11)
     printf("Congratulations, you found it! Number of guesses: %d ", num_guesses);
else
  printf("You did not found it! Number of guesses: %d ", num_guesses);
return 0;
}
int check(int n,int number)
{
//TODO: place your code here
   for(num_guesses=1;num_guesses<=10&&guess!=number;num_guesses++) //for loop placed here instead of while
   {
  if(guess>0&&guess<11)
  {
   if(guess > number)
   {
    printf("%d is too high ", guess);
   }
   else
   {
    printf("%d is too low ", guess);
   }
   // Repeat by asking for another guess
   printf("Enter another guess: ");
   scanf("%d", &guess);
  }
  else
  {
   num_guesses--;
   scanf("%d", &guess);
  }
}
return num_guesses;
}


Output:-
i)
Guess-A-Number Game!
Enter a number between 1 and 10
5
5 is too low
Enter another guess: 22
5
5 is too low
Enter another guess: 41
5
5 is too low
Enter another guess: 8
8 is too low
Enter another guess: 10
Congratulations, you found it! Number of guesses: 5


Process exited normally.
Press any key to continue . . .
ii)
Guess-A-Number Game!
Enter a number between 1 and 10
1
1 is too low
Enter another guess: 2
2 is too low
Enter another guess: 10
10 is too high
Enter another guess: 10
10 is too high
Enter another guess: 2
2 is too low
Enter another guess: 10
10 is too high
Enter another guess: 1
1 is too low
Enter another guess: 1
1 is too low
Enter another guess: 10
10 is too high
Enter another guess: 2
2 is too low
Enter another guess: 1
You did not found it! Number of guesses: 11


Process exited normally.
Press any key to continue . . .