#include <stdio.h> int main() { int i, j; int IsPrime; printf("The three digit prime numbers are:\n"); for(i=100;i<1000;i++) { IsPrime = 1; for(j=2;j<i;j++) //check divisibility with all but 1 and itself { if(i%j==0) //if divisible then it's not a prime number { IsPrime = 0; //not a prime number break; //no need to check divisibilty further as it's divisible by some no. } } if(IsPrime==1) { printf("%d \n", i); //print only if the no. is not divisible by any other no. except itself or 1, i.e. it's prime no. } } return 0; }
This blog is all about my experiments with Embedded Systems and Bluetooth, in general. There are a lot of blogs and articles which cover several aspects related to programming languages, devices, etc.. Not everything out there is easy to understand and this is my attempt to make it comprehensible. It’s more of an exact account of my work/projects/assignments. Enjoy!
Saturday, 18 November 2017
Programs on C - All three digit prime numbers
A prime number is a number which is either divisible by 1 or itself, hence, we need to check if the number is divisible by any number but itself and 1. If the remainder is zero on checking this condition then the number is not a prime number.
Labels:
C program,
Cprogramming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment