• How to use use 2 function prototype and array in C programming

    Zaragoza Member

    Need help with my C program (for assignment)….

    i need to use 2 function prototype and array
    the question is to display prime number for number -10,0,1,2,4,9,11,12

    #include
    
    int prime1 (int myArray []);
    int main(){
       int i;
       int a;
    
       int myArray [8] = {-10,0,1,2,4,9,11,12};
    
        //To print all the elements of the array
        printf ("This number will be checked if prime number of not\n");
       for (int i=0;i<8;i++){
        printf(" %d", myArray[i]);
       }
       
       prime1 (myArray []);
    
       return 0;
    }
    
    int prime1 (int myArray []){
       int a,i,count;
       
       for (a = 0;a <8;a++){
           for(i=2;i<=a/2;i++){
            if(a%i==0){
             count++;
                break;
            }
            else{
           continue;
        }
        }
       
       if(count==0 && a!= 1)
            printf("%d is a prime number\n",myArray [a]);
       else
          printf("%d is not a prime number\n",myArray [a]);
    }
    } 
    
  • SapnaVishwas Member

    At line 19, just call prime1(myArray).

    Also, you program at its current form does not work.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish