Search
 
SCRIPT & CODE EXAMPLE
 

C

recursion c prime number

    #include<stdio.h>

int isPrime(int,int);

int main(){

    int num,prime;

    printf("Enter a positive number: ");
    scanf("%d",&num);

    prime = isPrime(num,num/2);

   if(prime==1)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);

   return 0;
}

int isPrime(int num,int i){

    if(i==1){
        return 1;
    }else{
       if(num%i==0)
         return 0;
       else
         isPrime(num,i-1);
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: printf n characters c 
C :: C Variable Byte Sizes 
C :: print name of file argv c 
C :: #include <sys/time.h int main() { timespec ts; // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD clock_gettime(CLOCK_REALTIME, &ts); // Works on Linux } 
C :: mongodb delete all documents 
Dart :: flutter get width of screen 
Dart :: python read json from url 
Dart :: flutter transparent appbar 
Dart :: button shape flutter 
Dart :: datetime dart format print 
Dart :: make a rounded container flutte 
Dart :: Keyboard Pushes Text Fields off screen flutter 
Dart :: Flutter: Setting the height of the AppBar 
Dart :: flutter close app programmatically 
Dart :: how to hide notficition bar in flutter 
Dart :: flutter snackbar color 
Dart :: flutter android x 
Dart :: raisedbutton flutter 
Dart :: alertdialog flutter barrierColor 
Dart :: flutter screen size 
Dart :: operators in dart 
Dart :: flutter duration to string 
Dart :: compute flutter 
Dart :: empty widget flutter 
Dart :: mainAxisAlignment vs crossAxisAlignment flutter 
Dart :: dart function as variable 
Dart :: double to animation in flutter 
Dart :: flutter date input field 
Dart :: flutter string to date time 
Dart :: get length of map flutter 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =