#include <stdio.h>
char p ;
char q ;// global variable
char diamond ();
void info (char l, char m);
void main() //main program
{
char z,w;
printf("****************************************** *****\n\n");
diamond ();
info (p,q);
printf("****************************************** *****\n\n");
}
char diamond () //displays instructions to the user
{
printf("Eter the 1st character = ");
scanf("%c",&p);
printf("\n");
printf("Eter the 2nd character = ");
scanf("%c",&q);
printf("\n");
return (p,q);
}
void info (char l, char m) //prints shape of a diamond on the screen
{
int a,b,c ;
int x,y,z;
int temp =4;
for( x=0 ; x<4 ;x++) //for the fist half of diamond
{
for( y=0 ; y<temp ;y++)
{
printf(" ");
}
temp--;
printf("%c" ,l);
for( z=0 ; z<2*x-1 ;z++)
{
printf("%c" ,m);
}
if(x != 0 ) printf("%c" ,l);
printf(" ");
}
for(a=3; a>0 ;a--) //for the second half of diamond
{
for(b=a-1; b<4; b++)
{
printf(" ");
}
printf("%c" ,l);
for(c=0; c<2*(a-1)-1 ; c++)
{
printf("%c" ,m);
}
if(a != 1){printf("%c" ,l);}
printf("\n");
}
}
#include <stdio.h>
char p ;
char q ;// global variable
char diamond ();
void info (char l, char m);
void main() //main program
{
char z,w;
printf("****************************************** *****\n\n");
diamond ();
info (p,q);
printf("****************************************** *****\n\n");
}
char diamond () //displays instructions to the user
{
printf("Eter the 1st character = ");
scanf("%c",&p);
printf("\n");
printf("Eter the 2nd character = ");
scanf("%c",&q);
printf("\n");
return (p,q);
}
void info (char l, char m) //prints shape of a diamond on the screen
{
int a,b,c ;
int x,y,z;
int temp =4;
for( x=0 ; x<4 ;x++) //for the fist half of diamond
{
for( y=0 ; y<temp ;y++)
{
printf(" ");
}
temp--;
printf("%c" ,l);
for( z=0 ; z<2*x-1 ;z++)
{
printf("%c" ,m);
}
if(x != 0 ) printf("%c" ,l);
printf(" ");
}
for(a=3; a>0 ;a--) //for the second half of diamond
{
for(b=a-1; b<4; b++)
{
printf(" ");
}
printf("%c" ,l);
for(c=0; c<2*(a-1)-1 ; c++)
{
printf("%c" ,m);
}
if(a != 1){printf("%c" ,l);}
printf("\n");
}
}




මේකෙ වෙන්න ඕනි main එක ඇතුලේ info function එක call වෙන්න. info call උනාම එකේදී තමයි user ට කියන්නේ Letters 2ක් input කරන්න කියලා.
ඊට පස්සේ ඒ letters 2 parameters 2ක් විදිහට යවලා diamond function එක call වෙනවා.
එහෙම නේද?



#include <stdio.h>
int main()
{
int i,j,k;
printf("Select Size \n");
scanf("%d",&k);
for(i=1; i<=k; i++)
{
for(j=1; j<=k-i; j++)
{
printf(" ");
}
for(j=1; j<=2*i-1; j++)
{
printf("*");
}
printf("\n");
}
for(i=1; i<k; i++)
{
for(j=1; j<=i; j++)
{
printf(" ");
}
for(j=2*k-2*i-1; j>=1; j--)
{
printf("*");
}
printf("\n");
}
return(0);
}
#include <stdio.h>
int main(){
int x,y;
for( x=1;x<10;x++){
for( y=0;y<x;y++)
printf("*");
for( y=0;y<(10-x);y++)
printf("~");
for( y=0;y<(10-x);y++)
printf("~");
for( y=0;y<x;y++)
printf("*");
printf("\n");
}
for( x=9;x>0;x--){
for( y=0;y<x;y++)
printf("*");
for( y=0;y<(10-x);y++)
printf("~");
for( y=0;y<(10-x);y++)
printf("~");
for( y=0;y<x;y++)
printf("*");
printf("\n");
}
}
D:\>a
*~~~~~~~~~~~~~~~~~~*
**~~~~~~~~~~~~~~~~**
***~~~~~~~~~~~~~~***
****~~~~~~~~~~~~****
*****~~~~~~~~~~*****
******~~~~~~~~******
*******~~~~~~*******
********~~~~********
*********~~*********
*********~~*********
********~~~~********
*******~~~~~~*******
******~~~~~~~~******
*****~~~~~~~~~~*****
****~~~~~~~~~~~~****
***~~~~~~~~~~~~~~***
**~~~~~~~~~~~~~~~~**
*~~~~~~~~~~~~~~~~~~*