Skip to content
Snippets Groups Projects
Select Git revision
  • 2023ws
  • 2024ws default
  • 2022ws
  • 2021ws
  • 2020ws
  • 2018ws
  • 2019ws
  • 2017ws
  • 2016ws
9 results

hanoi-32.c

Blame
  • loesung-3.c 1.31 KiB
    #include <stdio.h>
    
    int fun_1 (char *s1, char *s2)
    {
      int result = 1;
      for (int i = 0; s1[i] && s2[i]; i++)
        if (s1[i] != s2[i])
          result = 0;
      return result;
    }
    
    int fun_2 (char *s1, char *s2)
    {
      int result = 1;
      for (int i = 0; s1[i] && s2[i] && result; i++)
        if (s1[i] != s2[i])
          result = 0;
      return result;
    }
    
    int fun_3 (char *s1, char *s2)
    {
      for (int i = 0; s1[i] && s2[i]; i++)
        if (s1[i] != s2[i])
          return 0;
      return 1;
    }
    
    int fun_4 (char *s1, char *s2)
    {
      int result = 1;
      for (int i = 0; s1[i] && s2[i]; i++)
        if (s1[i] != s2[i])
          {
            result = 0;
            break;
          }
      return result;
    }
    
    int main (void)
    {
      char *s1 = "Apfel";
      char *s2 = "Apfelkuchen";
      if (fun_1 (s1, s2) && fun_2 (s1, s2) && fun_3 (s1, s2) && fun_4 (s1, s2))
        printf ("OK\n");
      else
        printf ("failed\n");
      s1 = "Apfelkuchen";
      s2 = "Apfel";
      if (fun_1 (s1, s2) && fun_2 (s1, s2) && fun_3 (s1, s2) && fun_4 (s1, s2))
        printf ("OK\n");
      else
        printf ("failed\n");
      s2 = "Birnenmarmelade";
      if (fun_1 (s1, s2) || fun_2 (s1, s2) || fun_3 (s1, s2) || fun_4 (s1, s2))
        printf ("failed\n");
      else
        printf ("OK\n");
      s1 = s2;
      s2 = "Apfelkuchen";
      if (fun_1 (s1, s2) || fun_2 (s1, s2) || fun_3 (s1, s2) || fun_4 (s1, s2))
        printf ("failed\n");
      else
        printf ("OK\n");
      return 0;
    }