Six stock prices (buying price) are stored into a 2 x 6 two-dimensional array. T
ID: 3804378 • Letter: S
Question
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]. Please provide C code for above problem. Thank you
Explanation / Answer
Here goes the required C program for the given question. Scanf and Printf are being used for input and output functionalities.
Code:
#include <stdio.h>
int main(void) {
// your code goes here
int price[6][2]={{10,0},{10,0},{10,0},{10,0},{10,0},{10,0}};
printf("Enter the stock prices of six stocks");
int i=0,j=0;
for(i=0;i<6;i++){
scanf("%d",&price[i][1]);
}
printf(" Stock BuyingPrice Current Price Profit If Sold ");
for(i=0;i<6;i++){
int stocknum=i+1;
printf("%d ",stocknum);
for(j=0;j<2;j++){
printf("%d ",price[i][j]);
}
int profit=price[i][1]-price[i][0];
printf("%d ",profit);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.