Advertisement
Asif_Anwar

shaan-problem2

Jul 14th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int isPrime(int num)
  4. {
  5.     int i;
  6.     for(i = 2; i*i <= num; i++) {
  7.         if(num % i == 0) return 0;
  8.     }
  9.     return 1;
  10. }
  11.  
  12. int main()
  13. {
  14.     int i = 0, num = 2;
  15.     int arr[20];
  16.     while(i < 20) {
  17.         if(isPrime(num)) {
  18.             arr[i] = num;
  19.             i++;
  20.         }
  21.         num++;
  22.     }
  23.     printf("Value of the 15th position of the array: %d\n", arr[14]);
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement