C program for prime number

To understand better please read the following post first, it will clear your concept of prime number What is prime number and Why 1 is not a prime number? #include<stdio.h> int main(){ int n, i,check; printf("Enter a positive number\n"); scanf("%d",&n); for(i=2;i<=n/2;i++){ if(n%i==0) { check = 1; break; } } if(check==1) printf("\n%d is not a prime number\n",n); else printf("\n%d is a prime number\n",n); return 0; } Logic: The above program takes an integer n to check whether it is prime and use two control variables...

Why 1 is not a prime number?

We know that the prime numbers are 2, 3,5, 7, 11, 13, … … …, it starts from 2 because One is not a prime number. Why one is not a prime number? It explanation is on the following. The fundamental theorem of arithmetic Or Factorization Theorem: The fundamental theorem of arithmetic states that every positive integer (except the number 1) can be represented in exactly one way apart from rearrangement as a product of one or more primes (MathWorld) From the definition we got two factors product of one or more primes can be represented...

Matrix addition and subtraction in C using arrays

Consider 4 matrices, A, B,C and D, we are going to add A and B and keep on C. (A+B = C). And will subtract B from A and keep it on D.(A-B=D). First we need to check that the number of rows of matrix A is equal to the number of rows of matrix B, Also we should perform the same check in case of column. But in our program we assume that number of rows of A and B are equal, as well as the column of A is equal to column of B. Then we goes c[00]=a[00]+b[00], c[01]=a[01]+b[01]… and so on. d[00]=a[00]-b[00], c[01]=a[01]-b[01]… and so on. Lets coding this simple Program. #include<stdio.h> int main(){ int a[10][10],b[10][10],c[10][10],d[10][10],...