C# :: Find Closest Star To The Earth

Apr 19, 2015

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.

View 1 Replies


ADVERTISEMENT

C :: How To Delete Number And Find Closest

Aug 3, 2014

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 ?

[Code]....

View 9 Replies View Related

C :: Find Closest Upper Value In Array For Any Input Int

Jul 29, 2013

I have this array (assume sorted) and i need to find out the closest upper value for any input int. Example:

Code:

/* bsearch example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* qsort, bsearch, NULL */

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?

View 1 Replies View Related

C/C++ :: Find Closest Arrival And Departure Times?

Nov 13, 2014

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);

[code]....

View 11 Replies View Related

C :: Draw Magen David Star

Apr 18, 2014

problem to draw magen david star ,i find code that draw pyramid of starts. how can i modify this code to receive magen david star ?

Code:
#include <stdio.h>
int main() {
int rows, star, spaces;
char bukva='A';
int number_of_stars = 6;
int number_of_rows = number_of_stars;

[Code]....

View 4 Replies View Related

C :: Print The Star Equilateral Triangle

Dec 23, 2014

I use photos to express it. The answer is:

Code:
int main(int argc, char *argv[], int n) {
int i,j;
for (i=1;i<=n/2+1;i++) {

[Code]....

View 3 Replies View Related

C# :: How To Fix Space For Output Of Star Triangle

Mar 7, 2015

When i set any 3 inputs length, the space should be move in right position. I try to fix the space move forward into 1 space, but don't know why it doesn't work. Specially, when the number is 4 or 5. The space didn't move 1 space.

using System;
class length{
static void Main(){
int i,j,k;
string star = "*";
string s1 ="";
string s2;
int[] nums = new int[] {3,4,5};

[Code] .....

View 2 Replies View Related

C++ :: Star Pyramid Program - Adding Stars?

Sep 13, 2013

I have written a star pyramid program, it adds two stars at a time but I want to rewrite the program so the stars double each time.

#include<iostream>
using namespace std;
int main() {
int a = 0, b = 8;
for (int c = 1; c < 10; c++) {
for (int space = b; space > 0; space--)

[Code] ...

View 1 Replies View Related

C/C++ :: Program To Print Irregular Star Pattern?

Oct 5, 2014

I am trying to write a program that will make a pattern of stars. The last line is really tripping me up. I have to make the code only using the printf("*"); printf(" "); printf("/n"); statements once. I want to accomplish this with a for loops and if statements.

It is supposed to look like this:

* - 5 spaces before *
* * - 4 spaces before *
* * * - 3 spaces before *
* * * * * * - 0 spaces before *

This is what I've tried so far:

main()
{
int i, j, k;
i=1;
j=1;

[Code]....

here are the links on codepad [URL]

I think my first approach is way off. But I think I am on to something in the second link. I'm trying to print the "*" and extra 2 times on the fourth line. In the second link the compiler appears to be ignoring the || operator. Is my syntax incorrect in the second attempt? How should I change my if statement to make this pattern work?

View 2 Replies View Related

C++ :: Closest Distance 2D Points?

Oct 29, 2014

In the following code I don't understand why am I splitting the y left and y right.

(closest distance between 2 points in 2D)

Am I splitting the y left and y right so that I can concatenate them afterwards and then build the strip,only according to these concatenated halves ?

PS : Finding the min. distance between sorted x right and x left works fine , only problem is with the strip.

#ifndef CLOSESTPAIR_H_
#define CLOSESTPAIR_H_
#include <float.h>
#include <math.h>
typedef struct Point2D {
double x;
double y;

[code].....

View 4 Replies View Related

C :: Loop Statement To Print Numbers From 1 To 10 In Reverse Order Separated By Star

Apr 21, 2013

Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :

10*9*8*7*6*5*4*3*2*1

i try to do it but it show me like this :

10*9*8*7*6*5*4*3*2*1*

how do i write to show me like the first one ?

View 10 Replies View Related

Visual C++ :: Closest Distance Between Two Line Segments

Oct 29, 2014

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.

P1 = (0.012711 ,-0.000688 ,-0.001097);
P2 = (0.012895 ,-0.000686 ,-0.001133);
Q1 = (0.012676 ,-0.000689 ,-0.000999);
Q2 = (0.012859 ,-0.000687 ,-0.001034);

P1new = (0.012712, -0.000689, -0.001095);
P2new = (0.012895, -0.000687, -0.001131);
Q1new = (0.012676, -0.000690, -0.000996);
Q2new = (0.012859, -0.000688, -0.001032);

Results when calculating self contact of 15000 line segments in a few tens of fibers, one big mess:

Any better algorithm/corrections?

View 1 Replies View Related

C/C++ :: Display Data From File Into 2D Array - Print Closest Bmi From Data

Mar 28, 2015

#include <iostream>
#include <fstream>
using namespace std;
int main() {
int r = 0;
int c = 0;
int num[17][15] = { 0 };
[Code] ...

// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:

Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual.
Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.

The table below is a portion of a typical BMI table.

BMI:202122232425262728293031323334
Height:
60102108113118123128133138143149154159164169174
61106111116122127132138143148153159164169175180
.
.
.

MY task is to write a program that does the following things:

1.Produce the table by reading in the data from bmi.txt (on Moodle) into a 2-D array.

2. Display the table neatly on the screen, with row and column headings. The BMI should go from 20 to 34. The height should go from 60 to 76 inches.

3. Prompt the use for their height (in inches) and their weight.

4. Make the program print the closest BMI.

If their weight is lower than the values on the table, use 20 as the BMI.
If their weight is higher than the values on the table, use 34 as the BMI.

5.Loop the program so the user can find more BMI’s.

View 7 Replies View Related

Visual C++ :: Finding Value In Data File Closest To Calculated Data?

Jan 11, 2014

I'm reading from a file the middle column of data (Volts) where my test file "AP.txt" is opened by my program. Here is a segment of the data:

time Volts dV
49552 -66.20183 -0.01556807
49553 -67.76025 -0.01556495
49554 -69.30704 -0.01533247
49555 -70.81799 -0.0148486
49556 -72.26774 -0.0141133
49557 -73.63226 -0.01315276
49558 -74.89141 -0.01201764

Since the calculation I performed gives me -71.77 Volts, I need to match this value to the time that this occurs closest to using my program, and output the time that this occurs at.

Here is my program so far:
int main()
{
std::ifstream inFile;
inFile.open("AP.txt");
ofstream results_file ("maxvaluewithinput.txt");
float TimeAtdVMax = 0;
float VoltsAtdVmax = 0;

[Code]...

If you're curious, this program isn't for homework. It's part of the independent learning on C++ I'm doing for a Master's Thesis; the program will eventually model the APD90 of a ventricular action potential.

View 10 Replies View Related

C :: Finding The Closest Number To Another Number

Apr 10, 2014

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.

Example: | 4 - 3 | = 1;
1Darray = 1.

Full 1 Dimensional Array:
3 1 6 9

Full 2 Dimensional Array:
4 9 1 5
6 1 7 3
0 8 2 6

To compute the value of the first row in the 2D array,
| 4 - 3 | + | 9 - 1 | + | 1 - 6 | + | 5 - 9 | = 18.
| 6 - 3 | + | 1 - 1 | + | 7 - 6 | + | 3 - 9 | = 10.
| 0 - 3 | + | 8 - 1 | + | 2 - 6 | + | 6 - 9 | = 17.

Thus row 1 being the closest row to the 1 dimensional array.

The code I've written so far seems to be going down the right path. Have a look below...

Code:
int i,j,tempRow,tempTotal = 0,firEle,cloRow;
firEle = abs( x[0][0] - y[0] );

for( i = 0; i < size; i++ ) {
tempRow = 0;
for( j = 0; j < size; j++ ) {
tempRow += abs( x[i][j] - y[j] );

[Code] ....

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.

View 5 Replies View Related

C++ :: How To Find S In N

Mar 11, 2013

I need to find S and how did you find S in N is 4

#include <iostream>
int main () {
int n,i,s;
cout<<"Put the number of n"<<endl;
cin>>n;
s=0
for (i=1;i<=n;i++)
s=s+i
cout<<"S is<<s<<endl;
return 0
}

View 8 Replies View Related

C :: Find All Primes Between 0 And 100

Aug 20, 2013

I'm a beginner in C and system programming. I need to use multiple process and POSIX shared memory to find all primes between 0 and 100. My code compiles, but the result is not correct, it shows all the multiples of 3 as primes.My instructor also mentioned that the multi-process portion will fork() the appropriate number of child processes. The parent process will create a POSIX shared memory object to which the sub-processes will attach. I am confused about the things he said about parent process.why I'm not getting the right primes?

Code:

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/mman.h>

[Code]....

View 10 Replies View Related

C :: How To Find MIN And MAX From TXT File

Mar 16, 2013

I just got assigned a project in my C programming class. The objective is to find the min and max number out of a .txt file full of numbers on separate lines called "data.txt". I am pretty much stuck at this point. I don't know how to actually scan the file and print the min and max. Also, the list of numbers in the data.txt file contains hundred on hundreds of numbers. So I couldn't specify the exact amount of numbers listed in the file. I must also find the count number, sum, and the average of the given data, So far I have:

Code:

#include<stdio.h>
int main()
{
int counter=0;
int maximum=0, minimum=1;
int num_data_points, avg;
double max, min;
FILE *sensor;
sensor = fopen("data.txt", "r");

[Code]...

View 6 Replies View Related

C# :: Can't Find A Way To Compile

Aug 3, 2012

This is the first time I'm trying to program in C# and I'm having some trouble.I can't find a way to compile whatever I do.I don't think it's a problem of what I wrote but I might not have what is necessary.I tried: C:>csc fisrt.cs csc was not a valid command.

View 1 Replies View Related

C :: Find All Subsets With Sum Of X

Oct 20, 2013

I am working on a homework lab in which we have to find all the subsets equal to a given sum from an array of numbers.For example, an array of 7 numbers (1, 3, 4, 6, 7, 10, 25) with a sum of 25 would be (1, 3, 4, 7) and (25)...We are supposed to use dynamic programming to solve this.Now using the code below that we went over in class (Sedgewick's subsetSum), I understand how to this finds the first subset that adds up to the sum given. What's stumping me is how to find multiple subsets.

Code:

main(){
// Get input sequence
int n; // Size of input set
int m; // Target value
int *S; // Input set
int *C; // Cost table
int i,j,potentialSum,leftover;
}

[code]....

In class the teacher said it would be mainly just modifying the code we went over in class.

View 1 Replies View Related

C++ :: Cannot Find File Specified

Jun 9, 2014

when I try to run the program (new to VC++, I click the green arrow next to "Debug" in the toolbar, right) and I get a message box - code builds without errors - but the debugger says: "Unable to start program 'c:users/sal/documents/visual studio 2010/Projects/SFML App/Debug/SFML App.exe Cannot find file specified"...well, I go to the directory it says, and nothing is even in the Debug file.

View 10 Replies View Related

C++ :: How To Find Palindrome

Dec 2, 2013

how to get this program to find the palindrome? Here is my program:

#include <iostream>
#include <string>
using namespace std;
using std::string;

[code].....

View 2 Replies View Related

C++ :: How To Find The Nth Word

Nov 29, 2014

Would you use regex? (not sure how though)

Or, would you go through the hard way, and iterate through every word, until you discarded (n-1) words and reached the nth word?

The second wouldn't be so short and clear to one who reads the code, therefore i was wondering if there's a neater way.

View 1 Replies View Related

C/C++ :: How To Find Sum Of Even Factors

Nov 4, 2013

How to find the sum of even factors ????

View 1 Replies View Related

C++ :: Find The Most Isolated Feature On Map

Aug 25, 2013

Consider a map that has the following properties;
- the map is two dimensional
- the map is perfectly square with dimensions 10000000x10000000
- the map has an associated set of many features
- the map does not "wrap around"

Each feature on the map is described by a 2D coordinate in the range (0, 0) to (10000000, 10000000).

Find the most isolated feature on the map, where the "most isolated feature" is the feature that is furthest (largest Euclidean distance) from any other feature. Because the map does not "wrap around", this should be a direct distance across the map.

<----10000000---->
--------------- -
| A | |
| | |
| | 10000000
| | |
| B C | |
| E D | |
--------------- -

In the example above, A is the most isolated feature on the square map with edge length 10000000. Write a program that reads in many features from standard input, and outputs the name of the most isolated feature to standard output. The format of the input is the feature name, x coordinate and y coordinate separated by spaces.

Each feature is on a new line. There may be any number of features between 1 and 100000. The program should be fast, so the algorithm must be better than O(n^2).

Any of the following languages are fine - C++, Python (>=2.5), C#, Java. The program shouldn't require any third-party libraries other than the chosen language's standard libraries, and should be compilable and runnable on a modern Windows or Linux development environment of your choice (e.g. MS Visual Studio, gcc, Eclipse etc). You should submit your program source code and any necessary makefiles or project files required for compilation. If you write the code in C++, using C++11 features is fine.

View 1 Replies View Related

C++ :: Find Every Permutation With Length From 1 To N?

Jan 29, 2015

I need to be able to find every possible permutation using all possible values of a char. But I have to make it be able to form permutations from a length of 1 to variable N. For example, if N=3, I need it to be able to come up with

0x00
0x01
.......
0x00 0x00
0x01 0x01
.......
0xff 0xff 0xfe
0xff 0xff 0xff

How could I do this. (I would like to avoid recursion, since N might be as large as 50 or 60 and using recursion would most likely cause a stack overflow)

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved