Added previous assignments
This commit is contained in:
32
Assignment 4/main.c
Normal file
32
Assignment 4/main.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
*Student: S.K Soekhlal
|
||||
* Number: 4860632
|
||||
* Assignment: 3.3
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
|
||||
int is_prime(int number){ /*Function decleration and definition */
|
||||
int x;
|
||||
if(number < 2){ /*If number is 0 or 1, it is not prime*/
|
||||
return 0;
|
||||
}
|
||||
for(x=2; pow(x,2)<=number; x++){ /*using for loop to determine if input is not prime*/
|
||||
if (number%x == 0){ /*If remainder of input/x^2 = 0 then the number is not prime*/
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int lower_limit,upper_limit,i; /*Declaring variables*/
|
||||
scanf("%d%d",&lower_limit,&upper_limit); /*Storing user input in lower and upper limit variables*/
|
||||
for(i=lower_limit; i <= upper_limit; i++){ /*using for loop to call is_prime function to calculate if the number is prime*/
|
||||
if(is_prime(i) == 1){
|
||||
printf("%d\n",i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user