pastebin

Paste Search Dynamic
Recent pastes
number of stocks
  1. #include <stdio.h>
  2.  
  3. int main()
  4.  
  5. {
  6.  
  7.    int number_of_stocks, previous_day_stocks_price[50],current_day_stocks_price[50],c,d,i,K;
  8.  
  9.    float relative_stocks_price[50],temp=0.0f,a,b;
  10.  
  11.    printf("Enter the number of stocks: ");
  12.  
  13.    scanf("%d",&number_of_stocks);
  14.  
  15.    printf("Enter the previous day stocks prices of %d stocks.n",number_of_stocks);
  16.  
  17.    for(i=1;i<=number_of_stocks;i++)
  18.  
  19.    {
  20.  
  21.        scanf("%d",&previous_day_stocks_price[i]);
  22.  
  23.    }
  24.  
  25.    printf("Enter the current day stocks prices of %d stocks. n",number_of_stocks);
  26.  
  27.    for(i=1;i<=number_of_stocks;i++)
  28.  
  29.    {
  30.  
  31.        scanf("%d",&current_day_stocks_price[i]);
  32.  
  33.    }
  34.  
  35.    printf("Relative stock values of %d stocks is: ",number_of_stocks);
  36.  
  37.    for(i=1;i<=number_of_stocks;i++)
  38.  
  39.    {  
  40.  
  41.        a=current_day_stocks_price[i];
  42.  
  43.        b=previous_day_stocks_price[i];
  44.  
  45.        relative_stocks_price[i]=((a-b)/b)*100;
  46.  
  47.        printf("n%.2f%",relative_stocks_price[i]);
  48.  
  49.    }
  50.  
  51.    
  52.  
  53.    //Sorting the relative stocks price
  54.  
  55.    for (c = 0 ; c < number_of_stocks - 1; c++)
  56.  
  57.    {
  58.  
  59.    for (d = 0 ; d < number_of_stocks - c - 1; d++)
  60.  
  61.    {
  62.  
  63.      if (relative_stocks_price[d] > relative_stocks_price[d+1])
  64.  
  65.      {
  66.  
  67.        temp = relative_stocks_price[d+1];
  68.  
  69.        relative_stocks_price[d+1] = relative_stocks_price[d];
  70.  
  71.        relative_stocks_price[d] = temp;
  72.  
  73.      }
  74.  
  75.    }
  76.  
  77.  }
  78.  
  79.   printf("nThe sorted relative stock values are: n");
  80.  
  81.    for(i=1;i<=number_of_stocks;i++)
  82.  
  83.    {
  84.  
  85.        printf("%.2f t",relative_stocks_price[i]);
  86.  
  87.    }
  88.  
  89.  printf("n nEnter your lucky number K: ");
  90.  
  91.  scanf("%d",&K);
  92.  
  93.  printf("The %d smallest relative stock value is %.2f.",K,relative_stocks_price[K]);
  94.  
  95.    return 0;
  96.  
  97. }
  98.  
  99.  
Parsed in 0.014 seconds