Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  6-1
Language: C/C++
Code:
/*
 ============================================================================
 Name        : Labor_6-1.c
 Author      : Karl Batke
 Version     :
 Copyright   : (C) 2012 Labor EIN
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {

     //Variablen deklarieren
     int i,u,z,x,y,v,c;
     int schalt[6];                                        //Schalter S1-S5[0-4]+Lampe[5]
     char ein[10]="|Ein|";
     char aus[10]=" Aus ";
     char dest[60];

     //Initialisierung
     i=0;

     while(i<6){
          schalt[i]=0;
          i++;
     }
     for (i=0; i<60;i++) dest[i]=0;
          for (i=6; i<11;i++){
               ein[i]=0;
               aus[i]=0;
          }

     printf(" S1...S2...S3...S4...S5..Lampe\n");                    //Schaltzustand
     for (z=0;z<=1;z++){
          if (z==1) schalt[0]=1;
          else schalt[0]=0;
          for(x=0;x<=1;x++){
               if (x==1) schalt[1]=1;
               else schalt[1]=0;
               for(y=0;y<=1;y++){
                    if (y==1) schalt[2]=1;
                    else schalt[2]=0;
                    for(c=0; c<=1;c++){
                         if (c==1) schalt[3]=1;
                         else schalt[3]=0;
                         for (v=0; v<=1;v++){                         //Hauptbedingung
                              if (v==1) schalt[4]=1;
                              else schalt[4]=0;
                              if ((schalt[0]&&schalt[1])!=0){
                                   schalt[5]=1;
                              }
                              else if(((schalt[2]||schalt[3])&&schalt[4])!=0){
                                   schalt[5]=1;
                              }
                              else schalt[5]=0;
                              for(i=0;i<6;i++) {                         //String-schleife
                                   if (schalt[i]==1) strcat(dest, ein);
                                   else strcat(dest, aus);
                              }
                              printf("%s\n", dest);                    //Matrix-Ausgabe
                              for(i=0;i<60;i++) dest[i]=0;
                         }
                    }
               }
          }
     }
     return 0;                                                            //Programmende
}
Comments: