fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int fday =13, fmonth =5, cday, cmonth, passed, used;
  6. float min, max, ymax, ymin;
  7. printf("kalkulator\n");
  8. printf("podaj dzien: \n");
  9. scanf("%d", &cday);
  10. printf("podaj miesiac: \n");
  11. scanf("%d", &cmonth);
  12. printf("podaj zuzyte: \n");
  13. scanf("%d", &used);
  14. if(cmonth<fmonth)
  15. {
  16. printf("Podano bledny miesiac !");
  17. return 0;
  18. }
  19. if(cday>fday)
  20. passed=cmonth-fmonth;
  21. else
  22. passed=cmonth-fmonth-1;
  23. min=((20*passed)/12)-used;
  24. max=((26*passed)/12)-used;
  25. ymin=((20*7)/12)-used;
  26. ymax=((26*7)/12)-used;
  27. printf("jesli 20: %f , jesli 26: %f , w roku %f / %f \n", min, max, ymin, ymax);
  28. return 0;
  29. }
Success #stdin #stdout 0s 5304KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

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

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
kalkulator
podaj dzien: 
podaj miesiac: 
podaj zuzyte: 
jesli 20: -16102956.000000 , jesli 26: 86450168.000000 , w roku -32756.000000 / -32752.000000