Sponsored Content
Top Forums Programming Passed the compiler,but segementation fault Post 302091415 by zhshqzyc on Monday 2nd of October 2006 09:50:37 PM
Old 10-02-2006
Passed the compiler,but segementation fault

To find a number if it is a prime number, I cannot find any wrong.
Code:
#include <stdio.h>
#include <stdlib.h>

int isPrime(int valToCheck)
{
    int i;
    int retVal = 1;
    for(i=1;i<valToCheck;i++)
    {
        if(valToCheck%i == 0 && i != 1)
        {
           retVal = 0;
            break;
        }
    }
     return retVal;
}


int main()
{
   int x;
   int y;
   printf("Enter Number : ");
   scanf("%d\n",x);
   y = isPrime(x);
   if (y==1)
       printf("x is a prime\n");
   else
       printf("x is not a prime\n");
}

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

variable passed to awk

Anybody know what's wrong with this syntax? awk -v job="$job" 'BEGIN { FS="|"} {print $1,$2," ",$4," ",$3\n,$5,"\n"}' list It's keeping give me this message: awk: syntax error near line 1 awk: bailing out near line 1 It seems awk has problem with my BEGIN command. Any... (8 Replies)
Discussion started by: whatisthis
8 Replies

2. Shell Programming and Scripting

Awk:Segementation Fault

I am using awk command to sort a large file (7MB) and compare two files of 7 MB. The code is working fine for smaller files. But it gives following error for larger files Segmentation fault (core dumped) I am doing this on cygwin Please help in this regard Thanks Sandeep (1 Reply)
Discussion started by: sandeep_hi
1 Replies

3. UNIX for Dummies Questions & Answers

xl C/C++ compiler to GCC compiler

Hi, we are converting from IBM-AIX(xl c/c++ compiler) to Linux(GCC complier). As a part of this i need to change the CFLAGS. The xl c/c++ complier CFLAGS is CFLAGS := $(CDEBUG) $(PROJECT_INCLUDE_DIRS) $(COBJECT_MODE) -qcpluscmt -qmakedep -qcheck=all \ -qalign=bit_packed $(LINT_FLAGS)... (0 Replies)
Discussion started by: pbattu1
0 Replies

4. Programming

How Can a Machine Reads a Compiler Since A Compiler is Written in Text! Not Binaries?

To make a programming language you need a compiler, so what was the first programming language and how was is created if you need the compiler first? The compiler itself is considered as a high language comparing to the machine! since the compiler is not created in 1's and 0's... Eventhough i... (12 Replies)
Discussion started by: f.ben.isaac
12 Replies

5. Programming

fread: segementation fault(coredump) w/o stdlib.h

Hello All, I tried to test a sample fread example to read a complete file and the code is #include <stdio.h> #include <stdlib.h> int main () { FILE * pFile; long lSize; char * buffer; size_t result; pFile = fopen ( "test.xml" , "rb" ); if (pFile==NULL) {fputs ("File... (11 Replies)
Discussion started by: quintet
11 Replies

6. UNIX for Dummies Questions & Answers

cc compiler and gcc compiler

hi, can we install gcc compiler in unix based OS(sun solar,IBM AIX,HP,etc) and also can we install sun cc compiler in AIX environment and vice versa. and more ..is linux support cc compiler regards Ajay (3 Replies)
Discussion started by: ajaysahoo
3 Replies

7. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

8. What is on Your Mind?

I have passed RHCSA Exam

I have passed RHCSA Exam today. (1 Reply)
Discussion started by: ded325
1 Replies

9. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
BN_generate_prime(3SSL) 					      OpenSSL						   BN_generate_prime(3SSL)

NAME
BN_generate_prime, BN_is_prime, BN_is_prime_fasttest - generate primes and test for primality SYNOPSIS
#include <openssl/bn.h> BIGNUM *BN_generate_prime(BIGNUM *ret, int num, int safe, BIGNUM *add, BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg); int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg); int BN_is_prime_fasttest(const BIGNUM *a, int checks, void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg, int do_trial_division); DESCRIPTION
BN_generate_prime() generates a pseudo-random prime number of num bits. If ret is not NULL, it will be used to store the number. If callback is not NULL, it is called as follows: o callback(0, i, cb_arg) is called after generating the i-th potential prime number. o While the number is being tested for primality, callback(1, j, cb_arg) is called as described below. o When a prime has been found, callback(2, i, cb_arg) is called. The prime may have to fulfill additional requirements for use in Diffie-Hellman key exchange: If add is not NULL, the prime will fulfill the condition p % add == rem (p % add == 1 if rem == NULL) in order to suit a given generator. If safe is true, it will be a safe prime (i.e. a prime p so that (p-1)/2 is also prime). The PRNG must be seeded prior to calling BN_generate_prime(). The prime number generation has a negligible error probability. BN_is_prime() and BN_is_prime_fasttest() test if the number a is prime. The following tests are performed until one of them shows that a is composite; if a passes all these tests, it is considered prime. BN_is_prime_fasttest(), when called with do_trial_division == 1, first attempts trial division by a number of small primes; if no divisors are found by this test and callback is not NULL, callback(1, -1, cb_arg) is called. If do_trial_division == 0, this test is skipped. Both BN_is_prime() and BN_is_prime_fasttest() perform a Miller-Rabin probabilistic primality test with checks iterations. If checks == BN_prime_checks, a number of iterations is used that yields a false positive rate of at most 2^-80 for random input. If callback is not NULL, callback(1, j, cb_arg) is called after the j-th iteration (j = 0, 1, ...). ctx is a pre-allocated BN_CTX (to save the overhead of allocating and freeing the structure in a loop), or NULL. RETURN VALUES
BN_generate_prime() returns the prime number on success, NULL otherwise. BN_is_prime() returns 0 if the number is composite, 1 if it is prime with an error probability of less than 0.25^checks, and -1 on error. The error codes can be obtained by ERR_get_error(3). SEE ALSO
bn(3), ERR_get_error(3), rand(3) HISTORY
The cb_arg arguments to BN_generate_prime() and to BN_is_prime() were added in SSLeay 0.9.0. The ret argument to BN_generate_prime() was added in SSLeay 0.9.1. BN_is_prime_fasttest() was added in OpenSSL 0.9.5. 1.0.1e 2013-02-11 BN_generate_prime(3SSL)
All times are GMT -4. The time now is 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy