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


ADVERTISEMENT

C++ :: Find The Sum Of Primes Below Limit

Apr 15, 2013

I have to find the sum of primes below limit. My program works fine when I try to find primes less than 10. However, when I run it for the sum of primes less than 100, I get 166337 when I am supposed to get 1060. My program works on modular arithmetic, where any prime greater than 3 can be expressed as 1 or 5 mod 6.

Here is my code:

#include <iostream>
using namespace std;
int main(){
unsigned long long prime, sum;
int limit = 100;

[Code] ....

OUTPUT:
SUM: 166337

View 4 Replies View Related

C :: Print Primes In Limit

Jul 13, 2013

What's actually wrong with the program....I'm trying to print the primes in limit of L1 and L2 ;L1<L2.... */

Code:

#include<stdio.h>
#include<math.h>
void main(){
int L1,L2,n=0
printf("Enter Limits by a space:
}

[code]....

View 3 Replies View Related

C/C++ :: Making A Program That Gives All Primes Below A Given Number

Oct 8, 2014

I'm trying to understand why this won't work, the output i get is a list of even numbers. I'm trying to get all prime numbers below the number thats scanned in.

#include <stdio.h>
int isPrime(int number);
int main(){

[Code]....

View 5 Replies View Related

C/C++ :: Number Of Twin Primes Between Interval?

Feb 11, 2015

I'm having some trouble finishing my code, it's meant to give the number of twin primes between an interval e.g. 1 to 1000000 and the answer should be 8169 but all I can get it to is 8168

#include <stdio.h>
int prime (int num) {
int div;
if (num == 2) return 1;
if (num % 2 == 0) return 0;
div = 3;
while (div*div <= num) {

[code]....

View 6 Replies View Related

C++ :: Print Out Number Of Twin Primes Program

Jul 27, 2014

This program prints out the total number of up to 100,000. How to do is to print out the number of twin primes up to 100,000. Is it as simple as adding an if statement "if(primesList[j] - i == 2)"?

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
int primesCount = 0;

[Code] ......

View 4 Replies View Related

C++ :: Find Factors And Primes For A Range Of Numbers

Oct 9, 2014

I'm trying to write a program that will find all the factors and primes for a range of numbers. I have the inner loop working but I am having trouble writing the outer loop that will output the range of numbers instead of just finding the factors for one number.

int n1 = 0;
int n2;
int factor = 0;
cout << "Enter a starting number: ";
cin >> n1;
cout << "Enter a ending number: ";

[Code] ....

View 7 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 :: 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

C++ :: How To Find Each Pixel In The Circle

Jul 26, 2014

How can I find each and every pixel in a circle so that I can do some operations on it.

View 6 Replies View Related

C :: How To Find ASCII Value Of Given String

Aug 25, 2013

I know how to find find ASCII value of given character, but I am not getting how to find ASCII value of given string. For example I want to find ASCII value of string "HELLO",so how to do that.

View 13 Replies View Related

C :: Simple Version Of Find

Oct 28, 2013

Just wondering about how to write extremely simple version of 'find' in C: It just lists the path names of the files in the specified directories and all subdirectories.For example,

Code:

$find_version .
./foo
./bar
./baz
./baz/other

[Code]....

View 6 Replies View Related

C :: Find The Maximum Subsequence Sum

Mar 12, 2014

I got a code written in Java. But, I gave up writing code in Java. The program written is supposed to find the maximum subsequence sum. It's originally like this.

Code:
private static int maxSumRec (int [] a, int left, int right)
{
if(left == right)
if(a[left > 0])
return arr[left];

[Code] .....

I turned it into C, add some elements (to generate random numbers and change some variables' names), and becomes like this

Code:
int maxSumRec (val, left, right)
{
int x;
long int arr[val];
srand ( time(NULL) );
for(x=0; x<val; x++)

[Code] .....

It fails to compile. What have I done wrong? And I keep wondering why in the original code there is left and right variables and their values are never assigned. My c compiler (I use codeblocks) keeps telling me that. Idk why. My friend who keeps it in Java says it is fine but he cannot explain how his program works. What *is* left and right actually?

View 8 Replies View Related

C :: Find Minimum Value In Given Matrix M

Jun 16, 2013

The method doesn't work properly, the point of the code is to tell the minimum value in the given matrix "m", it's supposed to take the first value of the matrix store it in min_ and then compare it to every value of the matrix, if the value stored in min_ is bigger than the current value in the loop then it's stored as the new min_ and at the end it's supposed to print that minimum...

Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 3
void minimum (int mat[SIZE][SIZE]){
int r,c;
int min_;
printf("

[Code] ......

View 5 Replies View Related

C :: How To Find Maximum Value Of Array

Oct 29, 2014

Any way to determine the highest value of an array I created with random numbers. I am confused because the array needs to be initialized in the main, but populated in a function. I was able to populate it using a pointer variable and my results came out good for the initial array values and elements.

In order to figure out the max, I think I would need the results of the populated array. How do I do this when the populated array is stored in a pointer variable? Would I need to create a pointer to the first pointer I created? I tried creating another pointer to the initial array and printing that, but my results were not good.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code].....

View 10 Replies View Related

C :: How To Find First Bad Number From Float

Mar 6, 2015

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() == '

[Code]....

View 3 Replies View Related

C :: How To Find A Remainder Of A Division

Jun 11, 2013

I want to find the remainder of the division between a and b, but without using the reminder operator a%b.I thought to subtract b from a as long as a>b, that will give the remainder, but I don't know how to write it in code.

View 11 Replies View Related

C++ :: Cannot Find Included Class

Jan 13, 2013

I have the following file (I did everything in the .h file as I think that is a much cleaner way to do this, I realize my compile times will increase.

#ifndef PANEL_H
#define PANEL_H
#include <string>
#include "Container.h"
using namespace std;
}

[code]....

View 7 Replies View Related







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