CNIT 105 Assignment-08 Due: Wed. 03/21/18, by 11:50 pm 20 Points Objectives: o P
ID: 3733934 • Letter: C
Question
CNIT 105 Assignment-08 Due: Wed. 03/21/18, by 11:50 pm 20 Points Objectives: o Parallel Arrays o Finding max o Sequential Search Problem Description: Write a C program to store price of 20 objects in US dollars and in Euro in two parallel arrays Named Constants .Define a named constant for the size of the arrays 20 .Define the exchange rate of 1.3662 as a named constant. 1 Euro- 1.3662 US dollars main0 function: a) Declare an array of typeto store up to 20 prices (dollar amount). Name this b) Declare another array of the same size and typeto store prices in Euro. c) Write a loop to partially fill array price dollar by prompting the user in a loop. Usea array price. dellar Name this array price euro, sentinel value- -1 to stop the data entry > Store the price entered in array price dollax Convert the price to Euro using the exchange rate-store the Euro amount in the parallel array in the corresponding index. d) Display the number of values read into the array e) Write a loop to display both arrays in 2 columns with column headers ) Find the max price stored in array price dollar After the loop, display the max in US dollar and in Euro, g) Use the sequential search algorithm to display all the prices> $40 Inform the user if search fails. Grading Chart: Named Constant Declare parallel arrays Partially fill arrays in a loop Display # of entries Display both arrays with column headers MacBook Air
Explanation / Answer
#include<stdio.h>
#define ARRAY_SIZE 20;
#define EXCHANGE_RATE 1.3362
main()
{
//DECLARING PARELLEL ARRAYS
//NOTE:-represented DOLLARS as $ and EUROS as e
float price_dollar[20],price_euro[20];
int i,j;
int c;
while(i<20)
{
printf("Enter -1 to stop the data entry",i);
scanf("%f",&price_dollar[i]);
//PARTIALLY PILLING THE DATA IN THE LOOP IF IT IS REQUIRED
if(price_dollar[i]==-1)
{
price_dollar[i]=0.000000;
break;
}
price_euro[i]=EXCHANGE_RATE*price_dollar[i];
c=c+1;
i++;
}
//DISPLAYING NUMBER OF VALUES
printf("NUMBER OF VALUES PRESENT ARE:: %d ",c-1);
//DISPLAYING THE BOTH ARRAYS WITH THEIR COLUMN HEADINGS
printf("Detains in dollors Details in Euros ");
for(i=0;i<c-1;i++)
{
printf("$%f e%f ",price_dollar[i],price_euro[i]);
}
//FINDING MAX PRICES IN THE TWO LIST
printf("MAXIMUM ELEMENTS IN THE LISTS ARE:: ");
float maximum;
maximum = price_dollar[0];
for (i=0; i<20; i++)
{
if (price_dollar[i] > maximum)
{
maximum = price_dollar[i];
}
}
printf("Maximum PRICE in the Dollars list is::$%f ",maximum);
printf("Maximum PRICE in the Dollars list is::$%f ",maximum*EXCHANGE_RATE);
printf(" ");
//FINDING THE PRICES THAT ARE GREATER THAN $40
printf("PRICES GREATER THAN $40 ARE:: ");
int value=0;
for (i=0;i<20;i++)
{
if (price_dollar[i]>=40)
{
printf("$%f ",price_dollar[i]);
value=value+i;
}
}
if(value==0)
{
printf("THERE IS NO PRICE IS GREATER THAN $40");
}
}