Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. void elsoFeladat(int n){
  6.     for(int a=1; a<=n; a++){
  7.         for(int b=1; b<=n; b++){
  8.             for(int c=1; c<=n; c++){
  9.                 if(a<c && b<c && c<=n && a*a+b*b==c*c){
  10.                     printf("good: a = %d, b=%d, c = %d\n", a , b, c );
  11.                 } /*else {
  12.                     printf("nem jók: a = %d, b=%d, c = %d\n", a , b, c );
  13.                 }*/
  14.             }
  15.         }
  16.     }
  17. }
  18.  
  19. void masodikFeladat(int limit){
  20.     int a, b, c, i = 0;
  21.     //
  22.     int m = 2;
  23.     while (i<limit){
  24.         for(int n = 1; n < m; n++){
  25.             a = m*m - n*n;
  26.             b = 2*m*n;
  27.             c = m*m + n*n;
  28.  
  29.             i++;
  30.             printf("%d %d %d\n", a, b, c);
  31.         }
  32.         m++;
  33.     }
  34. }
  35.  
  36. void harmadikFeladat(int limit){
  37.     int a, b, c, i = 0;
  38.     //
  39.     int m = 2;
  40.     while (i<limit){
  41.         for(int n = 1; n < m; n++){
  42.             a = m*m - n*n;
  43.             b = 2*m*n;
  44.             c = m*m + n*n;
  45.  
  46.             i++;
  47.             if(a<b){
  48.                 printf("%d %d %d\n", a, b, c);
  49.             }
  50.         }
  51.         m++;
  52.     }
  53. }
  54.  
  55.  
  56.  
  57. int main(int argc, char* argv[]){
  58.     printf("add meg az argumentumot: ");
  59.     int task = atoi(argv[1]); //atoi = atof only for integers?
  60.     int n = atoi(argv[2]);
  61.  
  62.     if (task == 1){
  63.         printf("1.feladat, n = %d\n", n); //task number and n
  64.         elsoFeladat(n);
  65.     }
  66.     else if (task == 2) {
  67.         printf("1.feladat, n = %d\n", n);
  68.         masodikFeladat(n);
  69.     }
  70.     /*else if (task ==3) {}
  71.     else if (task ==4) {}*/
  72.     else {
  73.         printf("gebasz van!"); //ide jön h semmi sem fut le, valami gebasz lesz a main argumentumokkal
  74.         }
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement