Navigationskarta Insitutitionen för Datavetenskap Umeå Universitet

Kodexempel F2

#include <stdio.h>

int main(void)
{
	printf("Hello, world!");
	return 0;
}


#include <stdio.h>

int main(void)
{
	int x;
	
	x = 5;
	printf("x=%d", x);
	return 0;
}


#include <stdio.h>

int main(void)
{
	int x = 5;
	char tkn = 'A';
	
	printf("x=%d\ntkn=%c\n", x, tkn);
	return 0;
}

 #include <stdio.h>

/* Returnera summan av parametrarna */
int summa(int x, int y)
{
	return (x+y);
}

int main(void)
{
	int x = 5, y = 3;

	printf("Summan=%d\n", summa(x, y));
	return 0;
}


#include <stdio.h>

int main(void)
{
	int i;

	for (i = 0; i < 10; i++) {
		printf("%d\n", i);
	}

	i = 0;
	while (i < 10)	 {
		printf("%d\n", i);
		i++;
	}

	return 0;
}


...
do {
  printf("i: %d\n", i);
  i++;
} while (i < 22);
...


#include <stdio.h>

int main(void)
{
	int i, j;

	i = get_size();

	if (i > 100) {
		over_limit();
		i = adjust_value(i);
	}
	else go(i);
	
	if (j = i) printf("i is nonzero\n");
}


...
if (remove("gammalfil")) {
  printf("Filen kunde ej tas bort.\n");
  exit(1);
}
printf("OK.\n");
...


#include <stdio.h>

int main(void)
{
	int i;

	i = choice();

	switch (i) {
	case 1:	 copy_file();
		 break;
	case 2:	 confirm_delete();
		 delete_file();
		 break;
	case 3:	 print_file();
		 break;
	default: illegal_choice();
		 break;
	}
}
[an error occurred while processing this directive]