// by Sabrina Rispin
// Activity Section: 4
// Date: 9/4/15
// Description: Upon entering an odd number it will print a cross of nxn
// dimensions.
#include <stdio.h>
#include <stdlib.h>
void printCross (int n);
void printLine (int num, int count, int posHash1, int posHash2);
int main (int argc, char * argv[]) {
int num;
//printf("Please enter an odd number:\n");
scanf ("%d", &num);
printCross(num);
return EXIT_SUCCESS;
}
void printCross (int num) {
int count = 0;
int posHash1 = count;
int posHash2 = num - 1;
while (count < num) {
printLine(num, count, posHash1, posHash2);
posHash1++;
posHash2--;
count++;
}
}
void printLine (int num, int count, int posHash1, int posHash2) {
int i = 0;
while (i < num) {
if ((i == posHash1) || (i == posHash2)) {
printf ("#");
} else {
printf ("-");
}
i++;
}
printf ("\n");
}
Download file:
warmupPracExam.c
(969 bytes)