Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Need Help With C Program To Test If A Number Is Prime


18 replies to this topic

#11 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 25 February 2008 - 06:51 AM

check if a number is prime or not
Need Help With C Program To Test If A Number Is Prime

Replying to saga
It prints "not prime" for any number given as input whether its actually prime or not.

-reply by Bency

#12 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 27 April 2008 - 06:42 AM

plz print prime no from 1 to 100
Need Help With C Program To Test If A Number Is Prime

Please print prime no from 1 to 100


Its my assiment I have to complete it

-reply by syed jawwad alam

#13 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 27 June 2008 - 06:17 PM

object of a class
Need Help With C Program To Test If A Number Is Prime

I just want to know the javacoding to create object of a class.

-reply by suro

#14 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 30 October 2008 - 03:19 PM

c program that test numbers
Need Help With C Program To Test If A Number Is Prime

Assignment Description

Develop a program using the C language that will use a single subscripted array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is NOT a duplicate of a number already read. At the end the program should give a summary of how many numbers were entered and how many numbers were rejected and how many numbers were displayed.

Your program should use functions.

1. Function Readnum
Your program should prompt the user to input up to 20 numbers. [15 points]

2. Function Testnum
Next the program should test if the number has already been entered or not. If not, the number should be displayed

3. Function Summary
Finally the program should display the summary as follows;
Total numbers entered
Total numbers rejected because they were duplicates
Total numbers displayed


-question by Naemi Ngeno

#15 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 02 March 2009 - 07:44 AM

#include<stdio.H>#include<conio.H>#define PRIME 1#define NON_PRIME 0Void main(){int and,flag,I;Clrscr();Printf("Enter number:");Scanf("%d",&and);Flag=PRIME;    /* Assume Number is always PRIME */For(I=2;I<and;I++)  { if(and%I==0)    flag=NON_PRIME;  }if(flag==PRIME)  printf("and%d is PRIME",and);Else  printf("and%d is NOT PRIME.",and);getch();}



#16 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 02 March 2009 - 07:50 AM

Here is a simple C program for PRIMENeed Help With C Program To Test If A Number Is Prime

#include<stdio.H>#include<conio.H>#define PRIME 1#define NON_PRIME 0Void main(){int and,flag,I;Clrscr();Printf("Enter number:");Scanf("%d",&and);Flag=PRIME;    /* Assume Number is always PRIME */For(I=2;I<and;I++)  { if(and%I==0)    flag=NON_PRIME;  }if(flag==PRIME)  printf("and%d is PRIME",and);Else  printf("and%d is NOT PRIME.",and);getch();}

-reply by Ankit PokhrelKeywords:

#17 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 25 August 2009 - 05:06 AM

Plz help me i get Time limit exe... in 10200Need Help With C Program To Test If A Number Is Prime

 [10200]

#include<iostream>#include<math.H>Using namespace std;Int main(){   //freopen("1.Txt","r",stdin);   int a,b;   long long int c,pri[10000];   while((scanf("%d%d",&a,&b))==2)   {     int p,t=0,count=0;     for(p=a;p<=b;p++)     {       c=p*p+p+41;       long long int d=sqrt©;       long long int I;       int j=0;       for(I=1;I<=d;I++)       {         if(c%I==0)           j++;         if(j>1)           break;       }       if(j==1)       {           pri[t]=c;         t++;       }       count++;     }     float avg;     avg=float((t))/float(count)*100;     printf("%.2fand",avg);   }   return 0;}

-reply by Masum

#18 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 12 December 2009 - 02:10 PM

#include <stdio.H>#include<math.H>#include<conio.H>

main(){Clrscr();Printf("Enter a number: ");

int and;Scanf("%d", &and);

if(and == 2)Printf("%d is prime", and);Else if(and % 2 == 0 || and < 2)Printf("%d is not prime", and);Else{Int x;For(x = 0; x < (int)sqrt((double)and); x++)If(and % x == 0){Printf("%d is not prime", and);Return 0;}Printf("%d is prime", and);return 0;}

getch();Return 0;}

but it only answers 2 to 4...

-reply by kint

#19 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 02 February 2010 - 07:19 PM

number is prime or notNeed Help With C Program To Test If A Number Is Prime

#include<stdio.H>Main(){Int I,and;Printf("enter the number to be checkedand");Scanf("%d",&and);For(I=2;I<and;I++) { if(and%I==0)    {Printf("The number is not a prime numberand");Break;}Else{Printf("the number is a prime numberand");Break;   }}If(and==1){Printf("The number is neither a prime or nor a cmpositeand");} }

-reply by monish





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users