VF-

Untitled

VF-
Nov 18th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void int_beolvas(int* x);
  5. int negyzetszam_e(int szam);
  6. int count(int x);
  7.  
  8. int main() {
  9.     // fuggvenyek hivasa, eredmeny kiirasa
  10.  
  11.     int szam;
  12.  
  13.     int_beolvas(&szam);
  14.  
  15.     printf("1..%d közt %d négyzetszám van\n", szam, count(szam));
  16.  
  17.     return 0;
  18. }
  19.  
  20. int negyzetszam_e(int szam) {
  21.     // egy szamrol annak megallapitasa, hogy negyzetszam-e
  22.  
  23.     return pow(floor(sqrt(szam)), 2) == szam;
  24. }
  25.  
  26. int count(int x) {
  27.     // az osszegzes elvegzese
  28.  
  29.     int eredmeny = 0;
  30.  
  31.     for (int i = 0; i <= x; i++) {
  32.         if (negyzetszam_e(i)) {
  33.             eredmeny++;
  34.         }
  35.     }
  36.  
  37.     return eredmeny;
  38. }
  39.  
  40. void int_beolvas (int* x) {
  41.     // 1 db integer ertek ellenorzott beolvasasa
  42.  
  43.     while (1) {
  44.         printf("szám: ");
  45.         scanf("%d", x);
  46.  
  47.         if (*x >= 0) {
  48.             break;
  49.         }
  50.  
  51.         printf("Invalid input\n");
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment