Question

0001 #include <stdio.h> 0002 0003 #define NUM_PRODUCTS 2 0004 #define NUM_CATEGORIES 2 0005 #define NUM_DIGITS 2...

0001 #include <stdio.h>
0002
0003 #define NUM_PRODUCTS 2
0004 #define NUM_CATEGORIES 2
0005 #define NUM_DIGITS 2
0006
0007 struct ProductInfo
0008 {
0009     int prodID;
0010     int numberInStock;
0011     double unitPrice;
0012 };
0013
0014 int main(void)
0015 {
0016     struct ProductInfo productList[NUM_PRODUCTS] =
0017     {
0018         {78, 8, 19.95},
0019         {95, 14, 22.98}
0020     };
0021
0022     int categoryCount[NUM_CATEGORIES] = { 0 };
0023
0024     int i, j, sum, id, divisors[] = { 10, 1 };
0025
0026     for (i = 0; i < NUM_PRODUCTS; i++)
0027     {
0028         sum = 1;
0029         id = productList[i].prodID;
0030         for (j = 0; j < 2; j++)
0031         {
0032             sum *= id / divisors[j];
0033             id = id % divisors[j];
0034         }
0035         categoryCount[sum % NUM_CATEGORIES] += productList[i].numberInStock;
0036     }
0037
0038     for (i = 0; i < NUM_CATEGORIES; i++)
0039     {
0040         if (categoryCount[i] % 2 == 0)
0041         {
0042             printf("Category %d has %d items\n", i, categoryCount[i]);
0043         }
0044     }
0045
0046     return 0;
0047 }

each line that has code needs to be defined, can someone help me

Homework Answers

Answer #1

Line 0001 - importing standard I/O library

Line 0003 , Line 0004, Line 0005 - defining CONSTANT

Line 0001-0012 - defining structure ProductInfo with attributes: prodID as int, numberInStock as int, and unitPrice as double

Line 0014 - declaring main function

Line 0015 - 0020 - passing array productList to the structure.

Line 0022 - Initializing array

Line 0024 - defining variables i, j , sum, id as int type & array divisors also of int type.

Line 0026 -0036 - initializing for loop that will give id, sum of product and this sum & id passes to function categoryCount for total count.

Line 0038- 0044- for loop to find the total count of category

Line 0046 - Exit status of program.


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT