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

I am woundring if you can help me with this programm : Write a C program that as

ID: 3803140 • Letter: I

Question

I am woundring if you can help me with this programm :

Write a C program that asks the user for 7 numbers (positive integers) from 1 to 50. Generate 7 random numbers from 1 to 50 (hint: use srand(time(NULL)) and rand(), and (x%50)+1). Make a function called bubble that sorts a list of 7 numbers using the bubble sort algorithm (call bubble twice). Print out the users guess in the order given by the user and in numeric order. Print out the random numbers you generated in the order that you generated them and in numeric order (remember, both sets of numbers must be unique numbers). Let the user know how many and which numbers matched your lottery numbers. Be sure to give the user specific instructions.

Explanation / Answer

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


int bubble(int list[], int n) //n is the size of list
{
int c, d, t;

for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (list[d] > list[d+1])
{
//swap

t = list[d];
list[d] = list[d+1];
list[d+1] = t;
}
}
}
return 0;
}

int main()
{
int user[7],lottery[7];
int i,j=0;
srand(time(NULL));
for(i=0;i<6;i++)
lottery[i]=rand() % 50 + 1;
printf("Enter 7 numbers: ");
for(i=0;i<7;i++)
scanf("%i",&user[i]);
printf("the numbers in the order user entered: ");
for(i=0;i<6;i++)
printf("%i ",user[i]);
bubble(user,7); //calling bubble to sort user entered numbers
printf("numbers entered by user in ascending order: ");
for(i=0;i<6;i++)
printf("%i ",user[i]);
printf("lottery number generated: ");
for(i=0;i<6;i++)
printf("%i ",lottery[i]);
bubble(lottery,7); //calling bubble to sort random generated numbers
printf("lottery number generated in ascending order: ");
for(i=0;i<6;i++)
printf("%i ",lottery[i]);
for(i=0;i<7;i++)
{
    if(lottery[i]==user[i])
    {
        j++;
       }
   }
      printf("total number(s) that matched:%i ",j);
      if(j!=0)
{
       printf("number(s) that matched: ");
for(i=0;i<7;i++)
{

    if(lottery[i]==user[i])
    {
        printf("%i ",user[i]);
       }
   }
}
   return 0;
}


  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote