Write a function which takes string of integer numbers and length of a string. Function need to return value of element which is close to mean of all numbers and transform string without that element. If are more numbers in same "distance" of mean, function need to find first and throw that number-element.
In function without []..
with pointers.
I wrote this code below, programm find mean of elements and if mean is equal to any element of string.. the programm return that number. Idk how to delete that number and how to find closest.. for ex:
String=[4,7,10,3]
sum=24
mean=6
The progoramm need to delete 7 and new string look like String=[4,10,3]
insert Code:
#include <stdio.h>
int main()
{
int n,i;
printf("Elements of string ?
Consider a coordinate system for the Milky Way, in which the Earth is at (0; 0; 0). Model stars as points, and assume distances are in light years. The Milky Way consists of approximately 1012 stars, and their coordinates are stored in a file in comma-separated values (CSV) format one line per star and four fields per line, the first corresponding to an ID, and then three floating point numbers corresponding to the star location. How would you compute the k stars which are closest to the Earth? You have only a few megabytes of RAM.
int compareints (const void * a, const void * b) { return ( *(int*)a - *(int*)b );
[Code] ....
So whenever i hit something that is not in the array i would like to know the closes upper value. So for 4 closest upper value is 5, then for 8 it is 12 , for 35 it is 44. how would one do this?
I suspect it is a logical error but I can't pinpoint it. The assignment is to input a time of day in 24 hour format, pattern match with scanf, and print out the closest arrival and departure times for that time. The arrival and departure times are in minutes past midnight in a constant array. I am getting no bugs but the program is not giving correct values.
/* filename: hw25.c * Purpose: Finds the closest arrival and departure times */ #include <stdio.h> #include <stdlib.h> #define N 8 #define HOUR 60 void find_closest_flight(int desired_time, int *departure_time, int *arrival_time);
Try not to make too much fun of me for my logic, but I'm having trouble with this. I am trying to make it so the program takes a 1 dimensional array and a 2 dimensional array, and checks to see what row in the 2 dimensional array is the closest to the 1D array.
To compute the value of the 1D array you take the first row first element in the 2D array, and the first element in the 1D array, subtract and the absolute value.
The whole temp part is kind of confusing myself. What I'm thinking is that I can add all row values up using
Code: tempRow += abs( x[i][j] - y[j] ); , then I need to compare that value to see if it is close to the "firEle" which is value I need to get closest to.
// objects to hold results, row id, and name class result_holder { public: // initialize class members result_holder() : row_id(0), row_value(0.0), row_name("") { }
[Code] ....
There are cases where I need to find an object based on the value of row_id and delete the object from the vector row_results. I could find the proper object by looping through the vector and testing against each member.
Code: // id I am looking for unsigned int id_to_delete = 12; for(i=0; i<row_results.size(); i++) { if(id_to_delete == row_results[i].row_id) { delete row_results[i]; } }
I have used find before to find the position in a vector with a specific value, but I don't know how to use find to locate a specific value for an object member.
Also, is delete what I need to get rid of the object or should I be using erase as in,
Code: // id I am looking for unsigned int id_to_delete = 12; for(i=0; i<row_results.size(); i++) { if(id_to_delete == row_results[i].row_id) { row_results.erase(row_results.begin()+i); } }
The program should find and delete all vowels in a word that is user entered. This is what I have so far and I know it should be essentially this format I just don't know how to set enteredword and word equal to each other.
#include <string> #include <iostream> using namespace std; void vowelremover(string&); int main () { string word;
The program should find and delete all vowels in a word that is user entered. This is what I have so far and I know it should be essentially this format I just don't know how to set entered word and word equal to each other.
Code:
#include <string> #include <iostream> using namespace std; void vowelremover(string&); string word; int main () {//string word;
I have an assigment to make program which deletes from sentence all words with character count which is equal to pair number , for example - [ I like C ] and the result of this program should be [I C] because the word like contains 4 characters which is pair and it should be removed.
So I started writing my program and I am stuck at this block of code -
#include <stdio.h> #include <stdlib.h> main () { char text[100], blank[100]; int c=0,d=0,i,j; gets(text);
[Code] ....
To explain what is happening - I go through all string and search for first ' ' space symbol and check its value. If it is pair then my program prints that it is not pair[because last character before space had not pair number of characters], but the hardest part comes in when i have two not pair words , because space takes one character and now when i check if i%2 == 1 the answer is false [0] for the second word .
Any good algorithm for calculating the closest points/distance between two line segments? I use some pretty general code: [URL] ....
which seems widely used and advertized on the web and works in most cases but seems to often fail horribly when line segments are nearly parallel. I've been messing with the SMALL_NUM value for division overflow to no avail. The calculated distance can still vary widely when nearly parallel.
I managed to isolate a specific incident where this happens in my code. The distance between segments P1P2 and Q1Q2 changed abruptly in one timestep from 1.05 mm to 0.90 mm (yarn radius = 1 mm), causing abrupt compression spikes. In reality the distance in the original timestep is definitely also around 0.90 mm but is not calculated as such. I find that the values of s and t (s=0 for P1, 1 for P2, t=0 for Q1, 1 for Q2) for the closest points are originally 0 and 0 (as well as in the previous time steps) and then change abruptly to 0 and around 0.29 in the new time step. What it should be, I still need to check out.
I am trying to find the max number entered by the user, and it should terminate when a negative number is entered. For my code, it will just end when the user inputs a lower number than the previous. i.e.- 10 20 15 "The highest number is 20" when it should be "10 20 5 40 15 -1" "The highest number is 40". No arrays or do/while loops either.
#include <iostream> using namespace std; int Max(int x); int main() { int x;
I am entering numbers to float ... I want program to find out, which first number is not from specific interval. How to do it ? Example: Enter input : 5 10 20 30 50 46 . 30 is invalid. Here is the code :
Code:
while(scanf("%f",&input)!=EOF || input==0) { sum=input+sum; if (getchar() == '
I'm having this issue where my else if statements are not working. My program only works correctly when I go into my if statement and change the first part of my array to the specific row I am trying to find ex [0][i] to [1][i].
int getMonthMax(int scores[][COLS],int month){ int highestN=0,i, j; for (i=0;i<ROWS-1;i++){ if(scores[0][i]>highestN){ highestN=scores[0][i];
I have to manage a Clinic. I need to delete a booking (for example, if John said he's coming on March 22nd at 15:30 but then he say he's not going to come, I have to delete that booking so another person can use it).
idSearched: the id of the person that is not going to come. I have a lot of specialties and each one has a list. So I ask for the speciality to delete the node (the node contains John's booking). If I don't find it, I return (-1). searchSpecByID return a pointer to the list where the speciality is. So head will point to the first node of the list. In nodeToDelete I have the node I want to delete.
The program detects OK when is the first in the list and when not, but it doesn't delete the node.
I need to generate a grid of 10x8 and fill it with random numbers (max 70), then i need to find the smallest number within the random numbers generated and my "findSmallest" function does not seem to work and i do not know how to make it work...
Here my Code:
include <iostream> using namespace std; int main() { int row=0; int col=0; int ArrayGrid [9][11]; srand(time(NULL));
I have been struggling with this program. I am somewhat new to c and suck at logic. I have a personal program I want to make that I will try to get extra credit for in school. I have a printed set of winning lottery numbers form the last 10 years. I chose the easiest one do do logically which is just 5 numbers none repeating.
I am trying to find out how I can print the least common 10 sets. I think if there are any set which have not been picked I would have to print all of those because logically they would all be equal, then print sequentially the sets least picked up to 10.
I have pseudocode which I am sure is wrong but will post it just to show that I am trying. My first attempt was to add the numbers but quickly realized that that wouldn't work ...
5 Nums Pseudocode Code: Read Nums Parse Into Ints Make Array [185] //39+38+37+36+35 The highest the numbers added together can go
I use rand function to generate a number which consists of 3-5 digits(e.134,1435,73463..). The user decides whether he wants a 3 digit,4 digit or 5 digit number.After that,the user tries to guess the number.Its like mastermind game.The user will enter a number (with the same amount of digits) and the program will calculate how many digits from the secret number he has found and also how many digits he has found in the correct position(e.if the generatir produces the number 32541 and the user tries the number 49581 the program should tell him that he found 3 digits (5,1,4) and 2 digits in the correct position(5,1)) so that after some tries he finds the secret number.My problem is with the functions so that i can compare the digit of each number,find the amount of same digits and the amount of digits in same position.