Answer to Question #215899 in C for saa

Question #215899

Mr. Karan buys a lottery ticket. There are 5 numbers that are selected as winners in 5 regions. Check whether Mr. Karan won the lottery or not.

Requirements:

  1. Declare an array to store the lottery numbers and karan_num
  2. Read the lottery numbers and karan_num
  3. Check whether Mr. Karan won the lottery or not by performing searching operation.
1
Expert's answer
2021-07-11T14:33:48-0400
#include <stdio.h>
#include <stdlib.h>


int main(int argc, char* argv[])
{
    int i, j;
    int lottery_numbers[5];
    int karan_num;


    for (i = 0; i < 5; i++)
    {
        printf("enter lottery number of region %d: ", i + 1);
        scanf("%d", &lottery_numbers[i]);
    }


    printf("enter lottery number of Mr. Karan: ");
    scanf("%d", &karan_num);


    j = -1;
    for (i = 0; i < 5; i++)
    {
        if (lottery_numbers[i] == karan_num)
            j = i;            
    }   


    if (j >= 0)
        printf("Mr. Karan won the lottery\n");
    else
        printf("Mr. Karan did not win the lottery\n");


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS