04 June, 2013

C Program To Perform Character Design : #03.

This Post Contains A C Program To Perform Character Design With Correct Source Code, Algorithm & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Nested For-Loops' From C Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.



C Program To Perform Character Design :#03.
/* Declaration Of Header Files */
#include <stdio.h>
#include <conio.h>

/* Start Of Main Program */
int main()
{

 /* Declaration Of Variables */
 int num, row = 1, col = 0, space = 0;

 /* Asking For The Input From User */
 printf(" \n Enter Number of Rows For Design : ");
 scanf("%d",&num);

 /* Source Code For Computing ----- */
 for(; num>=1; num--, row++)
 {
  for(space = row; space>1; space--)
     printf(" ");

  for(col=1; col<=num; col++)
    printf("#");

  printf("\n");
 }

 getch();

 return 0;

}
/* End Of Main Program */

Output:
Enter Number of Rows For Design :  5
# # # # #
 # # # #
  # # #
   # #
    #

C++ Program To Perform Character Design :#03.
/* Declaration Of Header Files */
#include <iostream.h>
#include <conio.h>

/* Start Of Main Program */
int main()
{

 /* Declaration Of Variables */
 int num, row = 1, col = 0, space = 0;

 /* Asking For The Input From User */
 cout  <<  " \n Enter Number of Rows For Design : ";
 cin  >>  num;

 /* Source Code For Computing ----- */
 for(; num>=1; num--, row++)
 {
  for(space = row; space>1; space--)
     cout  <<  " ";

  for(col=1; col<=num; col++)
    cout  <<  "#";

  cout  <<  "\n";
 }

 getch();

 return 0;

}
/* End Of Main Program */

Output:
Enter Number of Rows For Design :  5
# # # # #
 # # # #
  # # #
   # #
    #




No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.

Blog Archive