Every line of this c program please explain. Thank you     Source Code: // include necessary header files # include # include # include int main(){                  // Use current time as seed

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Every line of this c program please explain. Thank you

 

 

Source Code:

// include necessary header files
# include<stdio.h>
# include<time.h>
# include<stdlib.h>

int main(){
        
        // Use current time as seed
    srand(time(0));
    
    // declare variables
        int arr[5][5] = {0}, user_num[5] = {0}, k = 1, i, j;
        int num[75] = {0}, n, flag, count, winner = 0;
        
        // initialize num array
        for(i = 0; i < 75; i++)
                num[i] = k++;
        
        // initialize the array cell with random numbers
        for(i = 0; i < 5; i++){
                for(j = 0; j < 5; j++){
                        while(1){
                                // generate random numbers
                                n = rand() % 75;
                                if(num[n] != 0){
                                        arr[i][j] = n + 1;
                                        num[n] = 0;
                                        break;
                                }
                        }
                        
                }
        }
        
        // display board
        printf("  B   I    N    G    O\n");
        printf("--------------------------\n");
        for(i = 0; i < 5; i++){
                for(j = 0; j < 5; j++){
                        printf("%3d |",arr[i][j]);
                }
                printf("\n--------------------------\n");
                printf("\n");
        }
        
        // take input of five numbers
        printf("Input 5 number combination: ");
        for(i = 0; i < 5; i++)
                scanf("%d",&user_num[i]);
                
        // make the position 0 for all aviable number
        // if not found then not a winner
        for(i = 0; i < 5; i++){
                flag = 0;
                n = user_num[i];
                for(j = 0; j < 5; j++){
                        for(k = 0; k < 5; k++){
                                if(arr[j][k] == n){
                                        user_num[i] = 0;
                                        arr[j][k] = 0;
                                        flag = 1;
                                        break;
                                }
                        }
                        if(flag == 1)
                                break;
                }
                if(flag == 0)
                        break;
        }

        if(flag == 0)
                printf("Not a winner!");
        else{
                // check horizontal
                for(j = 0; j < 5; j++){
                        count = 0;
                        for(k = 0; k < 5; k++){
                                if(arr[j][k] == 0)
                                        count++;
                                else
                                        break;
                        }
                        
                        if(count == 5){
                                printf("BINGO winner!");
                                winner = 1;
                                break;
                        }
                }

                if(winner == 0){
                        // check vertical
                        for(j = 0; j < 5; j++){
                                count = 0;
                                for(k = 0; k < 5; k++){
                                        if(arr[k][j] == 0)
                                                count++;
                                        else
                                                break;
                                }
                                
                                if(count == 5){
                                        printf("BINGO winner!");
                                        winner = 1;
                                        break;
                                }
                        }
                }
                
                if(winner == 0){
                        // check principal diagonal
                        count = 0;
                        for(j = 0; j < 5; j++){
                                if(arr[j][j] == 0)
                                        count++;
                        }
                        
                        if(count == 5){
                                printf("BINGO winner!");
                                winner = 1;
                        }
                }
                
                if(winner == 0){
                        // check secondary diagonal
                        count = 0;
                        if(arr[0][4] + arr[1][3] + + arr[2][2] + + arr[3][1] + + arr[4][0] == 0){
                                printf("BINGO winner!");
                                winner = 1;
                        }
                }
                
                if(winner == 0)
                        printf("No winner!");
        }
                
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY