VB icon

Prime numbers up to a given number

Email
Submitted on: 1/3/2015 11:25:00 AM
By: Harun Soylu (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: C
Views: 752
 
     This code prints the prime numbers to the screen up to a given number, and also find out if the given number is prime or not.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Prime numbers up to a given number
// Description:This code prints the prime numbers to the screen up to a given number, and also find out if the given number is prime or not.
// By: Harun Soylu (from psc cd)
//
// Assumes:This program read an integer value from the keyboard and print out all prime numbers that has an upper limit of input. I use four for loop to find and print all the numbers. This is my first program on this web-side I use linux platform to edit and compile and there is no error. If you have any questions or suggestions about the program please do not hesitate to contact with me.
//**************************************

#include "stdio.h"
int main(){
	
	int i,j,a,control=0,control2=0;
	
	printf("\nPlease write a number...");
	scanf("%d",&a);
	
	for(i=2;i<a;i++){
		for(j=2;j<i;j++){
			if(i%j==0){
				control2++;
				}
		}
			if(control2==0)
				printf("%d\n",i);
		
			if(a%i==0){
			control++;
			}
			
			control2=0;
	
	}
	
	if(control==0)
 	printf("\n%d is prime \n",a);
	else 
		printf("\n%d is not prime\n",a);
		return 0;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.