| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Need Help With C Program To Test If A Number Is Prime
#11
Posted 25 February 2008 - 06:51 AM
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
Posted 27 April 2008 - 06:42 AM
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
Posted 27 June 2008 - 06:17 PM
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
Posted 30 October 2008 - 03:19 PM
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
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
Posted 02 March 2009 - 07:50 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();}
-reply by Ankit PokhrelKeywords:#17
Posted 25 August 2009 - 05:06 AM
[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
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
Posted 02 February 2010 - 07:19 PM
#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 monish1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users




This topic is locked










