Digital-Systems-Assignments/Assignment 3/main.c
2019-09-12 08:55:54 +02:00

33 lines
826 B
C

/*
*Student: S.K Soekhlal
* Number: 4860632
* Assignment: 2.12
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
int a=0,i,temp=0; /*Declaring variables*/
scanf("%d",&a); /*Storing user input in variabl a*/
if(a < 2){ /*Testing if input is 0 or 1*/
printf("%d is not a prime number\n",a); /*We don't see 1 as a prime number*/
}
else
{
for(i=2; pow(i,2)<=a; i++){ /*using for loop to determine if input is not prime*/
if (a%i == 0){ /*If remainder of a/i = 0 then the number is not prime*/
temp = 1;
break;
}
}
if(temp == 1){
printf("%d is not a prime number\n",a);
}
else{
printf("%d is a prime number\n",a);
}
}
return 0;
}