#include <stdio.h>
#include <conio.h>
int main() {
int diamond_width, diamond_print_counter, diamond_line_counter, diamond_space = 1;
char diamond_symbol[]="c";
printf("/************************************************************\n * *\n * University of Nairobi *\n * School of Computing & Informatics *\n * *\n * Date: Tueday 12th February 2013 *\n * *\n * Write a program that prints a diamond *\n * The program should get from the user *\n * the symbol to use. *\n * The user should also provide *\n * the width of the diamond *\n *
printf("Please enter the symbol for making the diamond:\n");
scanf("%s",&diamond_symbol);
printf("Please enter the width of the diamond:\n");
scanf("%d", &diamond_width);
if (diamond_width%2==0)
{
diamond_width=((diamond_width/2));
printf("\nThe diamond width changed to size %d \nin order to make a true diamond\n\n", (2*diamond_width)-1);
}
else if (diamond_width%2==1)
{
diamond_width=((diamond_width/2)+1);
}
diamond_space = diamond_width - 1;
for ( diamond_line_counter = 1 ; diamond_line_counter <= diamond_width ; diamond_line_counter++ )
{
for ( diamond_print_counter = 1 ; diamond_print_counter <= diamond_space ; diamond_print_counter++ )
printf(" ");
diamond_space--;
for ( diamond_print_counter = 1 ; diamond_print_counter <= 2*diamond_line_counter-1 ; diamond_print_counter++)
printf("%s", diamond_symbol);
printf("\n");
}
diamond_space = 1;
for ( diamond_line_counter = 1 ; diamond_line_counter <= diamond_width - 1 ; diamond_line_counter++ ) {
for ( diamond_print_counter = 1 ; diamond_print_counter <= diamond_space; diamond_print_counter++)
printf(" ");
diamond_space++;
for ( diamond_print_counter = 1 ; diamond_print_counter <= 2*(diamond_width-diamond_line_counter)-1 ; diamond_print_counter++ )
printf("%s", diamond_symbol);
printf("\n");
}
return 0;
}
No comments:
Post a Comment