//1>program for piramid.
---------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,a,k=0,m;
clrscr();
scanf("%d",&n);
m=n*2;
a=m/2;
for(i=0;i<m;i++){
printf("\n");
if(i<a)k++;
else   k--;
for(j=0;j<m;j++){
if(i>=a||j<a-(k-1)||j>a+(k-1))
printf("  ");
else
printf(" *");
}
}
getch();
}

//2>program for Revrse piramid.
---------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,a,k=0,m;
clrscr();
scanf("%d",&n);
m=n*2;
a=m/2;
for(i=0;i<m;i++){
printf("\n");
if(i<a)k++;
else   k--;
for(j=0;j<m;j++){
if(i<a||j<a-(k-1)||j>a+(k-1))
printf("  ");
else
printf(" *");
}
}
getch();
}

//3>program for combind both piramid and Reverse Piramid.
---------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,a,k=0,m;
clrscr();
scanf("%d",&n);
m=n*2;
a=m/2;
for(i=0;i<m;i++){
printf("\n");
if(i<a)k++;
else   k--;
for(j=0;j<m;j++){
if(j<a-(k-1)||j>a+(k-1))
printf("  ");
else
printf(" *");
}
}
getch();
}

output........... 
for progaram 1
--------------------
   *
  ***
 *****
*******
------------------------
for progaram 2
--------------------
*******
 *****
  ***
   *
------------------------
for progaram 3
--------------------
   *
  ***
 *****
*******
 *****
  ***
   *

------------------------

Welcome to the forum, Dharma. :)

Two suggestions for your study in C:

1) for technical reasons, C should always have an int return from main. The correct format for main in these programs would be:

int main(void)

with

return 0; at the end of main.

I know void is taught sometimes, and shown in books, but that is wrong, and support for it may not continue in the future.

2) variable names like i,j,k,a,n, etc., are all good, but in this program, and in your programs in the future, it's a huge help to use descriptive variable names like row, rowNum, column or columnNum, etc. We all "get" and use i and j quite commonly, but the rest of those names - well, they could be improved.

Right now, I'm re-writing a program I wrote some years back (expanding it and upgrading it to 64 bit format), and it's a BIG help to have descriptive names for most of the variables where the purpose of it is not easily remembered years later.

commented: That was great suggestion.....Ill try to follow these from now on... +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.