Added previous assignments
This commit is contained in:
5
Assignment 3/.vscode/settings.json
vendored
Normal file
5
Assignment 3/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"stdio.h": "c"
|
||||
}
|
||||
}
|
32
Assignment 3/main.c
Normal file
32
Assignment 3/main.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
*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;
|
||||
}
|
Reference in New Issue
Block a user