Please provide C code for the following: Six stock prices (buying price) are sto
ID: 3804464 • Letter: P
Question
Please provide C code for the following:
Six stock prices (buying price) are stored into a 2 x 6 two-dimensional array. The user inputs the current price of each stock. This program will compare the buying price and the current price of each stock. It will print a table:
Stock Buying Price Current Price Profit If Sold
1 12.25 15.00 2.75
etc. After the table is displayed, print out the stock with the highest profit if sold and its position in the array[row][column].
Explanation / Answer
#include<stdio.h>
#include<conio.h>
void main()
{
float stock[2][6];
int i,max=0,stock_id=0;
printf("Enter the buying prices of each stocks");
for(i=0;i<6;i++)
scanf("%f",&stock[0][i]);
printf("Enter the current prices of each stocks");
for(i=0;i<6;i++)
scanf("%f",&stock[1][i]);
printf("Below is the comparision table for all the stocks: ");
printf("Stock Buying price Current price Profit if sold ");
max=0;
for(i=0;i<6;i++)
{
printf("%d %f %f %f ",i+1,stock[0][i],stock[1][i],stock[1][i]-stock[0][i]);
if(max<stock[1][i]-stock[0][i])
{
max=stock[1][i]-stock[0][i];
stock_id=i;
}
}
printf("stock with the highest profit if sold is %d and its position in the array %d",max,stock_id+1);
getch();
}
Sample Output :
Enter the buying prices of each stocks10.5
12.5
14.5
16.8
23.9
32.8
Enter the current prices of each stocks13.5
32.6
56.8
67.9
25.7
45.9
Below is the comparision table for all the stocks:
Stock Buying price Current price Profit if sold
1 10.500000 13.500000 3.000000
2 12.500000 32.599998 20.099998
3 14.500000 56.799999 42.299999
4 16.799999 67.900002 51.100002
5 23.900000 25.700001 1.800001
6 32.799999 45.900002 13.100002
stock with the highest profit if sold is 51 and its position in the array 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.