Skip to content
Snippets Groups Projects
Commit b3fdbb98 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiel-Programme 18.10.2021

parent 1df27ae5
Branches
No related tags found
No related merge requests found
Showing
with 302 additions and 0 deletions
#include <stdio.h>
int main (void)
{
int a = 1;
int b = 7;
while (a <= 10)
{
printf ("%*d * %d = %*d\n", a, 2, b, a * b, 2);
a++;
}
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 1;
int b = 7;
while (a <= 10)
{
printf ("%*d * %d = %*d\n", 2, a, b, 2, a * b);
a++;
}
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 1;
int b = 7;
char format[42];
sprintf (format, "%%%dd * %%d = %%%dd\n", 2, 2);
printf ("format = %s\n", format);
while (a <= 10)
{
printf (format, a, b, a * b);
a++;
}
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 1;
int b = 7;
char format[42];
snprintf (format, 42, "%%%dd * %%d = %%%dd\n", 2, 2);
format[41] = 0;
printf ("format = %s\n", format);
while (a <= 10)
{
printf (format, a, b, a * b);
a++;
}
return 0;
}
#include <stdio.h>
#include <stdint.h>
int main (void)
{
uint128_t f0 = 0;
uint128_t f1 = 1;
for (int i = 0; i < 100; i++)
{
printf ("f[%d] = %lu\n", i, f0);
uint128_t f2 = f0 + f1;
f0 = f1;
f1 = f2;
}
return 0;
}
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
int *p = prime;
for (int i = 0; i < 5; i++)
printf ("%d\n", *(p + i));
return 0;
}
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
int *p = prime;
for (int i = 0; i < 5; i++)
printf ("%d\n", p[i]);
return 0;
}
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
for (int i = 0; i < 5; i++)
printf ("%d\n", prime[i]);
return 0;
}
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
for (int *p = prime; p < prime + 5; p++)
printf ("%d\n", *p);
return 0;
}
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11, 0 };
for (int *p = prime; *p; p++)
printf ("%d\n", *p);
return 0;
}
#include <stdio.h>
int main (void)
{
int prime[] = { 2, 3, 5, 7, 11, 0 };
for (int *p = prime; *p; p++)
printf ("%d\n", *p);
return 0;
}
#include <stdio.h>
/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */
int is_leap_year (int year)
{
return 1;
}
int main (void)
{
int year = 2021;
while (!is_leap_year (year))
year++;
printf ("Nächtgelegenes Schaltjahr: %d\n", year);
return 0;
}
#include <stdio.h>
/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */
int is_leap_year (int year)
{
return 0;
}
int main (void)
{
int year = 2021;
while (!is_leap_year (year))
year++;
printf ("Nächtgelegenes Schaltjahr: %d\n", year);
return 0;
}
#include <stdio.h>
/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */
int is_leap_year (int year)
{
return 0;
}
int main (void)
{
int year = 2021;
while (!is_leap_year (year) && year < 2100)
year++;
printf ("Nächtgelegenes Schaltjahr: %d\n", year);
return 0;
}
#include <stdio.h>
/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */
int is_leap_year (int year)
{
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
return 1;
return 0;
}
return 1;
}
}
int main (void)
{
int year = 2021;
while (!is_leap_year (year) && year < 2100)
year++;
printf ("Nächtgelegenes Schaltjahr: %d\n", year);
return 0;
}
#include <stdio.h>
/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */
int is_leap_year (int year)
{
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
return 1;
return 0;
}
return 1;
}
return 0;
}
int main (void)
{
int year = 2021;
while (!is_leap_year (year) && year < 2100)
year++;
printf ("Nächtgelegenes Schaltjahr: %d\n", year);
return 0;
}
#include <stdio.h>
/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */
int is_leap_year (int year)
{
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
return 1;
else
return 0;
}
else
return 1;
}
else
return 0;
}
int main (void)
{
int year = 2021;
while (!is_leap_year (year) && year < 2100)
year++;
printf ("Nächtgelegenes Schaltjahr: %d\n", year);
return 0;
}
#include <stdio.h>
void hello (void)
{
printf ("Hello, world!\n");
}
int main (void)
{
hello ();
return 0;
}
#include <stdio.h>
int main (void)
{
hello ();
return 0;
}
void hello (void)
{
printf ("Hello, world!\n");
}
#include <stdio.h>
int main (void)
{
int foo = hello ();
printf ("foo = %d\n", foo);
return 0;
}
void hello (void)
{
printf ("Hello, world!\n");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment