Added previous assignments

This commit is contained in:
Shaquille K. Soekhlal
2019-09-12 08:55:54 +02:00
parent fc59dd3913
commit 395564a57a
7 changed files with 175 additions and 0 deletions

5
Assignment 3/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"stdio.h": "c"
}
}

32
Assignment 3/main.c Normal file
View 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;
}