index — ti25-glauchau-code @ 469fc8e16d8c0ec6fc321b0edcff427a031b1a0b

Meine Lösungen (oder auch nicht) für die Programmieraufgaben in der TI25 an der Staatlichen Studienakademie Glauchau

ima/2025-10-08/Musterpotenzmenge.cpp (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
using namespace std;                   // import everything from 'std' into current
#include <stdio.h>                     // Standard Input Output
#include <string.h>
int main (int argc, char* argv[]) {
  const int cardinality = 10;          // cardinality of the set
  const int elements = cardinality + 1;
  int control[elements];               // control vector
  char delimiter[3];                   // character string to be output between the data elements

  for (int i = 0; i < elements; control[i++] = 0); // initialize control vector
  while (control[0] == 0) {            // end of processing upon transfer to MSB
    printf ("{");                      // beginning of the set elements
    strcpy (delimiter, "");            // first elements without preceding characters
    for (int i = 1; i <= cardinality; i++) // analyze control vector
      if (control[i]) {                // Should the element be included in the result set?
        printf ("%s%d", delimiter, i - 1);
        strcpy (delimiter, ", ");
      }
    printf ("}\n");                    // end of set elements
    for (int i = elements; control[--i]++; control[i] = 0); // one addition
  }
  return 0;
}