Need help to write a code in c.
here are some values

And here are values of a,b and c. a = 1, b = 0.8, c= 0.5. equation for total is = (A*a) + (B*b) + (C*c)
I need help to write a code that iterates values of a,b,c in order of a > b > c to get h =2. h is random variable. It will continue iterating value of a,b,c until it gets h = 2.
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
char buffer[100];
int i=0,arr[10],sum,k;
float a=1,b=0.8,c=0.5,h,total;
fp = fopen("text.csv","r");
fgets(buffer, sizeof(buffer), fp);
//reading the file line by line
while(fgets(buffer, sizeof(buffer), fp) != NULL)
{
sum = 0;
i=0;
k = 0;
//In each line there are three numbers seperated by
','(12,34,17) so the three number are splited and stored into an
array
while(buffer[i]!='\n')
{
if(buffer[i]!=',')
{
sum = sum*10+(int)(buffer[i]-'0');
}
else
{
//if there is a ',' that implies
the number is ended so we will store the number into array
arr[k++]=sum;
//here if we print arr[k] it will
give the corresponding number
sum = 0;
}
i++;
}
arr[k++]=sum;
//calculating the total
total = arr[0]*a+arr[1]*b+arr[2]*c;
//printing the total sum
printf("%f\n",total);
//In the question it is mentioned that h is a random
variable and until h=2 we have to perform iterations.Since the csv
file contains five rows we have used %5 here.it will generate a
number between 1 to 5.whenever it generates 2 we will stop the
iterations.
h = rand()%5+1;
if(h==2)
{
//stop iterating when h =2
break;
}
}
}
If
you have any doubts please comment and please don't dislike.
deepika@deepika-Travel Mate- P243-M: ~/Desktop File Edit View Search Terminal Help deepika@deepika -TravelMate -P243 -M : ~/ Desktop$ gcc iterate.c deepika@deepika -TravelMate - P243 -M : ~/ Desktop$ /a . out 47.708001 50.099998 deepika@deepika -TravelMate -P243-M :~/ Desktop$ Wed 08:31 INI
Need help to write a code in c. here are some values And here are values...
9. Write some C++ code that will fill an array a with 20 values of type int read in from the keyboard. You need not write a full program, just the code to do this, but do give the declarations for the array and for all variables. 10. Suppose you have the following array declaration in your program: int your_array[7]; Also, suppose that in your implementation of C++, variables of type int use two bytes of memory. When you run...
here is the data and the code i
wrote for get some informations. i need to extrat the information
that it should be white in I column and >=50K in O
column. but my code is not working
Out [21]: White White White Black o <=50K <=50K <=50K <=50K Black <=50K White <=50K Black White White <=50K >50K >50K White >50K Black >50K 11 Asian-Pac-Islander >50K In [36]: df [(df ['I'] == 'White') & (df ['0'] == ' >50K )] #df/dfl'c']...
Hello, I need some help with a program in C++, the thing is that i need to subtract 7 from a Number(R) given until that number is between 0 and 6. Example R=20 20-7=13 13-7=6 then stop here R=30 30-7=23 23-7=16 16-7=9 9-7=2 then stop here.
Need some help making the 2nd line of this code functional, need the [Compare] function to validate the confirm email as the same as email. [Required] [EmailAddress] public string Email { get; set; } [Required] [DisplayName("Confirm Email")] [Compare] public string ConfirmEmail { get; set; }
Hi, I need help with my assignment. •Create a memory game in C •Function oriented with several functions •Structured programming •All cards are randomly placed on the board with face down •The player pick one card from the board and the symbol is shown •The player picks another card, with the aim to get pair (same symbol twice), and the symbol is shown •If two equal card is found (pair) the player gets one point and the pair is removed...
C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...
I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know, for each word in the dictionary,...
I need help writing a code in Java or C or python that follows the following requirements. 1. It prompts the user to enter values of the four integers (a, b, c, and M in this order) and prints out the first 100 elements (?0, ?1, ?2, …, ?99) of the sequence produced by the linear congruential random number generator for these parameters. Use a for loop and the following update formula: x = (a * x + b) %...
I need help writing this java program, here is what it wants me too code. Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.
I need some help for the calculations on Experiment # 22: Enthalpy, Entropy, and Free energy. For the reaction Zn(s) + CuSO4(aq) ⃡ ZnSO4(aq) + Cu(s), I need to: a. Calculate the values of the ΔS and the ΔH, showing units b. Calculate values of the change in G from equations 1 and 2, showing units. Here are my values: Temperature (K) Voltage (V), (E0) 333.15 1.120 328.15 1.117 323.15 1.112 318.15 1.109 313.15 1.106 308.15 1.105 303.15 1.104 298.15...