Programming Fundamentals
Information
- This page contains additional revision exercises for week 01.
- These exercises are not compulsory, nor do they provide any marks in the course.
- You cannot submit any of these exercises, however autotests may be available for some them (Command included at bottom of each exercise if applicable).
Exercise — individual:
Print a Simple Diamond
Create a program simple_diamond.c that prints a simple diamond shape that
uses / and \ for the outline.
Examples
dcc simple_diamond.c -o simple_diamond ./simple_diamond /\ \/
When you think your program is working,
you can use autotest
to run some simple automated tests:
1511 autotest simple_diamond
Sample solution for
simple_diamond.c
// Simple Diamond
// simple_diamond.c
//
// This program prints out a simple diamond.
#include <stdio.h>
int main (void) {
printf("/\\\n");
printf("\\/\n");
return 0;
}
Exercise — individual:
Print a Simple Triangle
Create a program called simple_triangle.c which prints a triangle.
Examples
dcc simple_triangle.c -o simple_triangle
./simple_triangle
^
/ \
/ \
/ \
/_______\
When you think your program is working,
you can use autotest
to run some simple automated tests:
1511 autotest simple_triangle
Sample solution for
simple_triangle.c
// Simple Triangle
// simple_triangle.c
//
// This program prints out a simple triangle.
#include <stdio.h>
int main(void) {
printf(" ^\n");
printf(" / \\\n");
printf(" / \\\n");
printf(" / \\\n");
printf("/_______\\\n");
return 0;
}