LegoDrifter

n broj odzemi go so pogolem prost od nego funkcija

Jan 27th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.     int prost(int n){
  4.     int i;
  5.     for(i=2;i*i<=n;i++)
  6.     {
  7.         if(n%i==0)
  8.         {
  9.             return 0;
  10.         }
  11.     }
  12.     return 1;
  13.     }
  14.  
  15.     int pogolemprost(int n)
  16.     {
  17.         n++;
  18.         while(!prost(n))
  19.         {
  20.             n++;
  21.         }
  22.         return n;
  23.     }
  24.  
  25. int main()
  26. {
  27.     int n;
  28.     scanf("%d",&n);
  29.     int dobivka=pogolemprost(n);
  30.     printf("%d - %d = %d\n",dobivka,n,dobivka-n);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment