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

Beispiele und Übungsaufgaben 5.10.2023

parent d2b1d93d
Branches
No related tags found
No related merge requests found
Showing with 299 additions and 0 deletions
#include <stdio.h>
int main (void)
{
printf ("Die Antwort lautet: ");
printf (42);
printf ("\n");
return 0;
}
#include <stdio.h>
int main (void)
{
printf ("Die Antwort lautet: ");
printf ("42");
printf ("\n");
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 42;
printf ("Die Antwort lautet: ");
printf (a);
printf ("\n");
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 42;
printf ("Die Antwort lautet: %d\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 13;
int b = 137
printf ("Die Antwort lautet: %d oder vielleicht auch %d\n", a, b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 13;
int b = 137;
printf ("Die Antwort lautet: %d oder vielleicht auch %d\n", a, b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 13;
int b = 137;
printf ("Die Antwort lautet: %X oder vielleicht auch %x\n", a, b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%d", &a);
a = 2 * a;
printf ("Das Doppelte ist: %d\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
#include <gtk/gtk.h>
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
File added
% hp-uebung-20231005.pdf - Exercises on Low-Level Programming / Applied Computer Sciences
% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Hello-World-Programme, Schaltjahr ermitteln, Maximum berechnen
\documentclass[a4paper]{article}
\usepackage{pgscript}
\thispagestyle{empty}
\begin{document}
\thispagestyle{empty}
\section*{Hardwarenahe Programmierung\\
Übungsaufgaben -- 5.\ Oktober 2023}
\exercise{Hello, world!}
Unter \url{https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/20231005}
können Sie
\href{https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/20231005/hp-uebung-20231005.pdf}%
{diesen Übungszettel als PDF-Datei}
herunterladen sowie die folgenden Beispielprogramme:
\begin{enumerate}[\quad(a)]
\item \gitfile{hp}{2023ws/20231005}{hello.c}
\item \gitfile{hp}{2023ws/20231005}{hello-gtk.c}
\end{enumerate}
Bringen Sie diese Programme auf Ihrem eigenen Rechner
und/oder auf einem Rechner der Hochschule
unter einem Betriebssystem Ihrer Wahl zum Laufen.
\file{hello.c} ist das klassische "`Hello, world!"'-Programm;
\file{hello-gtk} erzeugt ein Fenster mit einem Button zum Schließen.
(Wie diese Programme im einzelnen funktionieren,
wird im Laufe der Lehrveranstaltung erklärt werden.
In dieser Übung geht es nur darum,
sich mit dem Compilieren von C-Programmen vertraut zu machen.)
\textbf{Hinweis 0:} Diese PDF-Datei enthält Links zu den jeweiligen Dateien.
Durch Anklicken können Sie diese direkt herunterladen.
\textbf{Hinweis 1:} Für (b) benötigen Sie die Bibliothek GTK+.
Diese finden Sie -- einschließlich Dokumentation -- als freie Software im Internet.
\textbf{Hinweis 2:} Unter Unix mit \lstinline[style=cmd]{gcc}
funktioniert das Compilieren und Starten der Programme folgendermaßen:
\begin{lstlisting}[style=cmd]
gcc -Wall -O hello.c -o hello
./hello
gcc -Wall -O $(pkg-config --cflags gtk+-3.0) hello-gtk.c \
$(pkg-config --libs gtk+-3.0) -o hello-gtk
./hello-gtk
\end{lstlisting}
\exercise{Schaltjahr ermitteln}
Schreiben Sie ein Programm in einer beliebigen Programmiersprache
(z.\,B.\ C, Java, Python, Shell-Skript),
das eine Jahreszahl erfragt und ausgibt, ob es sich um ein Schaltjahr handelt.
\begin{itemize}
\item Wenn die Jahreszahl durch 4 teilbar ist, ist das Jahr zunächst einmal ein Schaltjahr.
\item Ausnahme: Wenn die Jahreszahl durch 100 teilbar ist, ist das Jahr kein Schaltjahr.
\item Ausnahme von der Ausnahme: Wenn die Jahreszahl durch 400 teilbar ist,\\
ist das Jahr doch wieder ein Schaltjahr.
\end{itemize}
\exercise{Maximum berechnen}
Schreiben Sie ein Programm in einer beliebigen Programmiersprache,
das 5 Zahlen erfragt und anschließend die größte dieser Zahlen ausgibt.
\end{document}
#include <stdio.h>
int main (void)
{
int a = 360;
printf ("a = %d\n", a);
int b;
printf ("Bitte b eingeben: ");
scanf ("%d", &b);
printf ("a / b = %d\n", a / b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 360;
printf ("a = %d\n", a);
int b;
printf ("Bitte b eingeben: ");
scanf ("%d", &b);
if (b = 0)
printf ("Bitte nicht durch 0 teilen.\n");
else
printf ("a / b = %d\n", a / b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 360;
printf ("a = %d\n", a);
int b;
printf ("Bitte b eingeben: ");
scanf ("%d", &b);
if (b == 0)
printf ("Bitte nicht durch 0 teilen.\n");
else
printf ("a / b = %d\n", a / b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 360;
printf ("a = %d\n", a);
int b;
printf ("Bitte b eingeben: ");
scanf ("%d", &b);
if (b == 0)
printf ("Bitte nicht durch 0 teilen.\n");
printf ("Das macht man nicht.\n");
else
printf ("a / b = %d\n", a / b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 360;
printf ("a = %d\n", a);
int b;
printf ("Bitte b eingeben: ");
scanf ("%d", &b);
if (b == 0)
printf ("Bitte nicht durch 0 teilen.\n");
printf ("Das macht man nicht.\n");
else
printf ("a / b = %d\n", a / b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 360;
printf ("a = %d\n", a);
int b;
printf ("Bitte b eingeben: ");
scanf ("%d", &b);
if (b == 0)
{
printf ("Bitte nicht durch 0 teilen.\n");
printf ("Das macht man nicht.\n");
}
else
printf ("a / b = %d\n", a / b);
return 0;
}
#include <stdio.h>
int main (void) { int a = 360; printf ("a = %d\n", a); int b; printf
("Bitte b eingeben: "); scanf ("%d", &b); if (b == 0) { printf
("Bitte nicht durch 0 teilen.\n"); printf ("Das macht man nicht.\n");
} else printf ("a / b = %d\n", a / b); return 0; }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment