The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C Code
Posted by: 12efawf | March 6, 2011 @ 6:02pm
C Code
[
Download
]
#include <stdio.h> void main() { // Incremental counting variables, used for counters for loops int i, j, x; // Regular variables to determine tree size, amount of spaces and total spaces int tree_Size, spaces, total_Spaces; // Character variables for each characer inputted by the user char tree_Characters, tree_Top, tree_Trunk, tree_Base, tree_Middle, null_Terminator; printf("Enter characters to use --> "); scanf("%c", &tree_Top); // Determine whether the first character holds any data if (tree_Top == '\n') { printf("Fail, tree_Top is null\n"); return; } else if (tree_Top != '\n') scanf("%c", &tree_Trunk); // Determine whether the second character holds any data if (tree_Trunk == '\n') { printf("Fail, tree_Trunk is null\n"); return; } else if (tree_Trunk != '\n') scanf("%c", &tree_Base); // Determine whether the third character holds any data if (tree_Base == '\n') { printf("Fail, tree_Base is null\n"); return; } else if (tree_Base != '\n') scanf("%c", &tree_Middle); // Determine whether the fourth character holds any data if (tree_Middle == '\n') { printf("Fail, tree_Middle is null\n"); return; } else if (tree_Middle != '\n') scanf("%c", &null_Terminator); /* Determine whether the fifth character holds any data, if it does, display an error message and terminate the program */ if (null_Terminator != '\n') { printf("Fail, null_Terminator is NOT null\n"); return; } // If it does not hold data, continue with program execution else if (null_Terminator == '\n') { printf("Enter size of tree --> "); scanf("%d", &tree_Size); // Check if size of tree does not exceed 20 or fall below 1 if (tree_Size < 1 || tree_Size > 20) { printf("\n"); printf("ERROR: Must enter a tree size between 1 and 20!"); } else { //For handling top part of tree for (i = 0; i <= tree_Size; i++) { printf("\n"); total_Spaces = tree_Size - i; //Determine spaces before each number for pyramid for (spaces = 1; spaces <= total_Spaces; spaces++) printf(" "); //Make first line always one number for (j = -1; j < i; j++) if (j <= -1) printf("%c", tree_Top); else if (j > -1) printf("%c%c", tree_Top, tree_Top); } //For handling stem and base of tree for (i = 0; i <= tree_Size; i++) { //if handling stem if (i < tree_Size) { printf("\n"); for (spaces = 1; spaces <= tree_Size; spaces++) printf(" "); printf("%c", tree_Trunk); } //else if handling base else if (i == tree_Size) { printf("\n"); for (x = 0; x < tree_Size; x++) { printf("%c", tree_Base); } printf("%c", tree_Middle); for (x = 0; x < tree_Size; x++) { printf("%c", tree_Base); } } } } } printf("\n"); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.59 / 8
88 Votes
http://codebin.yi.org/1154
page generated in 0.00 seconds