I am new to C language ,please help me .
Well i am writing a code to make a square of asterisks. but i can't figure how to make the square completely. Here's my code :
#include<stdio.h>
int main(void){
int n;
for(n=1;n<5;n++){
printf("*");
}
for (n=1;n<4;n++){
printf("*\n");
}
for (n=1;n<=5;n++){
printf("*");
}
for(n=5;n<=1;n--){
printf("*\n");
}
getchar();
return 0;
}
Thanks !!
it Should Exacxtly be Like
*****
* *
* *
* *
*****
Since you wish to create a hollow square of asterisks:
Think about how you'd create it. After some thought, you'll realize that:
The first and last rows are all asterisks.
For all other rows, the first and last columns of those rows are all asterisks.
Everything else is a space.
Using that, we can construct:
const int n = 5;
for(int i=0; i < n; i++) {
for(int j=0; j < n; j++) {
if (i == 0 || i == n - 1) {
printf("*");
}
else if(j == 0 || j == n - 1) {
printf("*");
}
else {
printf(" ");
}
printf(" ");
}
printf("\n");
}
Which can be put into a general solution for a n*m case:
const int ROWS = 5;
const int COLS = 5;
for(int i=0; i < ROWS; i++) {
for(int j=0; j < COLS; j++) {
if (i == 0 || i == ROWS - 1) {
printf("*");
}
else if(j == 0 || j == COLS -1) {
printf("*");
}
else {
printf(" ");
}
printf(" ");
}
printf("\n");
}
You're making it overly complicated - try this:
#include <stdio.h>
int main(void)
{
printf("*****\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("*****\n");
return 0;
}
#include <stdio.h>
#include <string.h>
#define LINE_SIZE 32
int main(void){
int i, n = 5;
char line1[LINE_SIZE] = {0}, line2[LINE_SIZE] = {0};
memset(line1, ' ', sizeof(line1)-1);
memset(line1+sizeof(line1)-n-1, '*', n);
memcpy(line2, line1, sizeof(line1));
memset(line2+sizeof(line2)-n, ' ', n-2);
puts(line1);
for(i = n-2; i ; --i)
puts(line2);
puts(line1);
return 0;
}
void print_square(int size)
{
int i;
int j;
for(i = 0; i < size; i++)
{
printf("*");
}
printf("\n");
for(i = 1; i < size - 1; i++)
{
printf("*");
for(j = 1; j < size - 1; j++)
{
printf(" ");
}
printf("*");
printf("\n");
}
for(i = 0; i < size; i++)
{
printf("*");
}
printf("\n");
}
#include<stdio.h>
main()
{
int n;
for(n=1;n<4;n++){
printf("*");
}
for (n=1;n<4;n++){
printf("* *\n");
}
for (n=1;n<=5;n++){
printf("*");
}
for(n=5;n<4;n--){
printf("*\n");
}
getch();
}
#include<stdio.h>
#include<string.h>
#define row 70
#define coloumn 70
#define buff_size row*coloumn
int draw_Box(int x,int y,int height,int width,int pixel_width,char *);
typedef struct
{
char r;
char g;
char b;
char a;
}rgba_t;
typedef struct
{
int x;
int y;
int height;
int width;
int pixel_width;
char * base_ptr;
}box_t;
rgba_t *rgba_ptr;
unsigned char data[buff_size]={1};
void main()
{
long unsigned int status,i,j=0;
memset(data,' ',sizeof(data));
if(status = draw_Box(28,28,15 ,15,3,data))
{
printf("out of boundary");
return ;
}
for(i=0;i<buff_size;i++)
{
if(i%coloumn==0)
{
if(i==0)
{
}
else
{
printf("%3d\n\n",(j++));
}
}
printf("%2c ",data[i]);
}
printf("%3d\n\n",j);
for(i=0;i<coloumn;i++)
{
printf("%2d ",i);
}
return ;
}
int draw_Box(int x,int y,int height,int width,int thick,char *base_ptr)
{
int x1,y1,i,j;
x1 = x + height-1;
y1 = y + width-1;
// char *box_base_ptr = (base_ptr+((x*10)+y));
if((x1)>row || (y1) >coloumn)
{
return 1;
}
#if 1
for(j=0;j<thick;j++)
{
for(i=x+j;i<=x1-j;i++)
{
*(base_ptr+(i*coloumn)+y+j)=0x31+j;
*(base_ptr+(i*coloumn)+y1-j)=0x31+j;
}
}
#endif
#if 1
for(j=0;j<thick;j++)
{
for(i=y+1+j;i<y1-j;i++)
{
*(base_ptr+((x+j)*coloumn)+i)=0x31+j;
*(base_ptr+((x1-j)*coloumn)+i)=0x31+j;
}
}
#endif
return 0;
// for(i=x;)
}
Related
I tried to make a program for solving the matrix using gauss elimination, but I don't know, how in line 9. replace "cals" where should be a count of columns but it is local in main.
So, how can I fix it?
Is there any way to put the number of columns in the matrix?
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <conio.h>
#include <time.h>
void gauss(double (*matrix)[cals], int cals, int rows)
{
int x = 1;
int y = 0;
int z = 0;
for(int check = 0; check < rows-1;check++)
{
for(int j = x;j<rows;j++)
{
if(matrix[j][z] == 0)
{
break;
}
float help = (matrix[j][z] / matrix[y][z])*-1;
for(int i = y; i < cals;i++)
{
matrix[j][i] = help*matrix[y][i]+matrix[j][i];
}
}
y++;
x++;
z++;
}
for(int i = 0; i < rows;i++)
{
for(int j = 0; j < cals; j++)
{
if(matrix[i][j] > 9 || matrix[i][j] < -9)
{
printf("%.0f ", matrix[i][j]);
}
else
{
printf(" %.0f ", matrix[i][j]);
}
}
printf("\n");
}
}
int main()
{
int rows = 3;
int cals = 3;
srand(time(NULL));
double matrix[rows][cals];
for(int i = 0; i < rows;i++)
{
for(int j = 0;j < cals;j++)
{
matrix[i][j] = rand() %9 + 1;
}
}
gauss(matrix, cals, rows);
return 0;
}
the Question is: to get from the user sodoku board and if there is a solution to print it, if not to print no solution!
the solution of the soduko: two identical numbers mmust not appear on the same line;
two identical numbers must not appear in the same colum.
I worte a program that works perfectly when I put the soduko board and the size (global parametes-as shown un my code) but when I tried to receive from the user it took so much time to run the solution and sometimes it didn't retun anything. I would like to understand why?!
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int matrix[5][5] = {
{4,2,0,0,5},
{2,0,0,1,3},
{5,0,1,2,0},
{0,0,3,0,2},
{0,0,0,0,0},
};
void print_sudoku()
{
int i,j;
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE;j++)
{
printf("%d ",matrix[i][j]);
}
printf("\n");
}
}
int number_unassigned(int *row, int *col)
{
int num_unassign = 0;
int i,j;
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE;j++)
{
if(matrix[i][j] == 0)
{
*row = i;
*col = j;
num_unassign = 1;
return num_unassign;
}
}
}
return num_unassign;
}
int is_safe(int n, int r, int c)
{
int i;
for(i=0;i<SIZE;i++)
{
if(matrix[r][i] == n)
return 0;
}
for(i=0;i<SIZE;i++)
{
if(matrix[i][c] == n)
return 0;
}
return 1;
}
int solve_sudoku()
{
int row;
int col;
if(number_unassigned(&row, &col) == 0)
return 1;
int i;
for(i=1;i<=SIZE;i++)
{
if(is_safe(i, row, col))
{
matrix[row][col] = i;
if(solve_sudoku())
return 1;
matrix[row][col]=0;
}
}
return 0;
}
int main()
{
if (solve_sudoku())
print_sudoku();
else
printf("No solution!\n");
return 0;
}
and this is whe code that I used to ask the user to enter a sodoku board:
int** ReadSoduko(int n) {
int** matrix = (int**) malloc((sizeof(int*)) * n);
for(int i = 0; i < n; ++i) {
matrix[i] = malloc(sizeof(int) * n);
}
printf("\nEnter your soduko board:\n");
for(int i = 0; i < n; ++i) {
printf("Enter row [%d]: ", i);
for(int j = 0; j < n; ++j) {
scanf("%d", &matrix[i][j]);
}
}
return matrix;
}
I suspect your problem is related to one thing: #define SIZE that you are probably forgetting to update when reading dynamically. Since you use SIZE in your loops, if that is not the real size of your matrix, then it probably won't work. I've changed 2 lines and added 3 other (the lines with comments at the end). Try it now.
#include <stdio.h>
#include <stdlib.h>
int SIZE; //changed here
int** matrix; //changed here
void print_sudoku()
{
int i, j;
for (i = 0; i < SIZE; i++)
{
for (j = 0; j < SIZE; j++)
{
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}
int number_unassigned(int* row, int* col)
{
int num_unassign = 0;
int i, j;
for (i = 0; i < SIZE; i++)
{
for (j = 0; j < SIZE; j++)
{
if (matrix[i][j] == 0)
{
*row = i;
*col = j;
num_unassign = 1;
return num_unassign;
}
}
}
return num_unassign;
}
int is_safe(int n, int r, int c)
{
int i;
for (i = 0; i < SIZE; i++)
{
if (matrix[r][i] == n)
return 0;
}
for (i = 0; i < SIZE; i++)
{
if (matrix[i][c] == n)
return 0;
}
return 1;
}
int solve_sudoku()
{
int row;
int col;
if (number_unassigned(&row, &col) == 0)
return 1;
int i;
for (i = 1; i <= SIZE; i++)
{
if (is_safe(i, row, col))
{
matrix[row][col] = i;
if (solve_sudoku())
return 1;
matrix[row][col] = 0;
}
}
return 0;
}
int** ReadSoduko(int n) {
int** matrix = (int**)malloc((sizeof(int*)) * n);
for (int i = 0; i < n; ++i) {
matrix[i] = (int*) malloc(sizeof(int) * n);
}
printf("\nEnter your soduko board:\n");
for (int i = 0; i < n; ++i) {
printf("Enter row [%d]: ", i);
for (int j = 0; j < n; ++j) {
scanf("%d", &matrix[i][j]);
}
}
return matrix;
}
int main()
{
printf("Size of matrix: "); //added this
scanf("%d", &SIZE); //added this
matrix = ReadSoduko(SIZE); //added this
if (solve_sudoku())
print_sudoku();
else
printf("No solution!\n");
return 0;
}
And don't forget that the matrix that you have declared statically doesn't have a solution! I have tested the same matrix, just replacing the 2 in first line by a 0 and it worked here.
So I'm creating a sudoku solver in C. Here's my full code as of now, I've mostly been using python and just got into C, I basically converted a lot of python functions to C to get this but I think it'll work:
#include <stdio.h>
#include <stdlib.h>
int is_empty();
int possible_v();
int solver();
int main(){
int s_array[9][9];
FILE * fpointer;
int i;
int j;
fpointer = fopen("sudoku001.txt", "r");
for (i=0; i<9; i++){
for(j = 0; j<9; j++){
fscanf(fpointer, "%d", &s_array[i][j]);
}
}
for (i=0; i<9; i++) {
if (i % 3 == 0) {
printf("------------------------------\n");
}
for (j = 0; j < 9; j++) {
printf(" %d ", s_array[i][j]);
if ((j + 1) % 3 == 0) {
printf("|");
}
}
printf("\n");
}
solver(s_array);
for (i=0; i<9; i++) {
if (i % 3 == 0) {
printf("------------------------------\n");
}
for (j = 0; j < 9; j++) {
printf(" %d ", s_array[i][j]);
if ((j + 1) % 3 == 0) {
printf("|");
}
}
printf("\n");
}
return 0;
}
int is_empty(int board[9][9]){
int i;
int j;
int is_empty= 0;
for (i=0; i<9; i++){
for(j = 0; j<9; j++){
if (board[i][j] == 0) {
is_empty = 1;
break;
}
}
if (is_empty == 1){
break;
}
}
return is_empty;
}
int possible_v(int board[9][9], int i, int j) {
int p_array[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int x;
int y;
int temp;
for (x = 0; x < 9; x++) {
if (board[x][j] != 0) {
temp = board[x][j];
p_array[temp - 1] = temp;
}
}
for (y = 0; y < 9; y++) {
if (board[i][y] != 0) {
temp = board[i][y];
p_array[temp - 1] = temp;
}
}
int m;
int n;
int temp1;
int temp2;
if (i>= 0 && i <= 2) {
m = 0;
}
else if (i>= 3 && i<=5) {
m = 3;
}
else{
m = 6;
}
if (j>= 0 && j <= 2) {
n = 0;
}
else if (j>= 3 && j<=5) {
n = 3;
}
else{
n = 6;
}
temp1 = m;
temp2 = n;
for (temp1; temp1<temp1+3; temp1++){
for (temp2; temp2<temp2+3; temp2++){
if (board[temp1][temp2] != 0){
p_array[board[temp1][temp2]] = 1;
}
}
}
temp1 = 1;
for (temp1; temp1<10){
if (p_array[temp1] == 0){
p_array[temp1] = temp1;
}
else{
p_array[temp1] = 0;
}
}
return p_array;
}
int solver(int board[9][9]){
int i;
int j;
int x;
int y;
int empty_check;
int p_values;
int temp;
if (is_empty(board) == 0){
printf("Board Completed");
empty_check = 0;
return empty_check;
}
else{
for (x = 0; x < 9; x++){
for (y = 0; y< 9; y++){
if (board[x][y] == 0){
i = x;
j = y;
break;
}
}
}
p_values = possible_v(board, i, j);
for (temp = 1; temp <10; temp++){
if (p_values[temp] != 0){
board[i][j] = p_values[temp];
solver(board);
}
}
board[i][j] = 0;
}
}
My main issue when compiling is getting the last two functions work with each other.
Function 'solver' calls and binds function 'possible_v'. Possible_V returns an array which I need to solve the puzzle. How can I make this work? .
You have the array locally declared, hence it cannot be passed back since it is destroyed once the function is exited. The workaround to this is to dynamically declare the array using malloc int *parray = (int*)malloc(9*sizeof(int)); and using the return type int* instead of int. But do not forget to free the allocated memory, else you will just keep allocating new memory from heap for every call you make.
As a side note, your implementation of Sudoku solver is a bit complex, and there is no need to return an array. You need to pass only the board. Here is an implementation of Sudoku Solver. This works both for 9x9 and 6X6 boards.
Edit : As advised by David Rankin, I have converted the C++ code to C.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int n;
int issafe(int **board,int i,int j,int num){
for(int k=0;k<n;k++)
if(board[i][k] == num || board[k][j] == num)
return 0;
int cellx,celly;
if(n==6){
cellx = (i/2)*2;
celly = (j/3)*3;
for(int l=cellx;l<cellx+2;l++)
for(int m=celly;m<celly+3;m++)
if(board[l][m] == num){
return 0;
}
return 1;
}
int root = sqrt(n);
cellx = (i/(root))*root;
celly = (j/(root))*root;
for(int l=cellx;l<cellx+root;l++)
for(int m=celly;m<celly+root;m++)
if(board[l][m] == num)
return 0;
return 1;
}
int solve(int **board,int i,int j){
if(i == n)
return 1;
if(j == n){
return solve(board,i+1,0);
}
if(board[i][j] != 0)
return solve(board,i,j+1);
for(int k=1;k<n+1;k++)
if(issafe(board,i,j,k)){
board[i][j] = k;
if(solve(board,i,j+1))
return 1;
//backtrack
board[i][j] = 0;
}
return 0;
}
int main(){
do{
printf("Enter size of board(9 or 6): ");
scanf("%d",&n);
}while(n != 9 && n != 6);
int **board;
board = malloc(sizeof *board * n);
for(int i=0;i<n;i++)
board[i] = malloc(sizeof *board * n);
// input
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&board[i][j]);
if(solve(board,0,0))
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
printf("%d ",board[i][j]);
printf("\n");
}
return 0;
}
I have a simple software for printing e circuit board in the console. I run the program below with the addBoard() (poorly named method for adding component) and it just runs printing nothing. Even though it is last in the sequence. If I comment it out the program works fine and prints everything out in the Visual Studio Code terminal window.
What could this be due to? (also any pointers on my usage of pointers hehe... or anything else that isn't best practice is hugely appreciated.) Thanks!
#include <stdio.h>
#include <stdlib.h>
char *posArr[10][30];
void printInstructions(){
printf("Hello and welcome! Here you can configure your own breadboard\n");
printf("To do this you will use coordinates using this syntax:\n");
printf("width: 3\n");
printf("height: 5\n");
printf("After that a component will be choosen.\n");
printf("It would look like below:\n");
}
void printBoard(){
for (int i = 1; i <= 10; i++) //Height
{
printf("\n");
for (int j = 1; j <= 30; j++) //Width
{
printf("%s", posArr[i][j]);
}
}
}
void clearBoard(){
for (int i = 1; i <= 10; i++) //Height
{
for (int j = 1; j <= 30; j++) //Width
{
posArr[i][j] = ". ";
}
}
}
void buildBoard(int *width, int *height){
//*height -= 1;
//*width -= 1;
for (int i = 1; i <= 10; i++) //Height
{
//printf("\n");
for (int j = 1; j <= 30; j++) //Width
{
if (*height == i && *width == j){
posArr[i][j] = "¤ ";
//printf("¤ ");
}
else {
posArr[i][j] = ". ";
//printf(". ");
}
}
}
}
void addBoard(){
int h, w;
while(1)
{
printf("Width: ");
scanf("%d", w);
printf("Height: ");
scanf("%d", h);
buildBoard(&w,&h);
//Add length later
printBoard();
}
}
int main() {
printInstructions();
int a=3, b=5;
buildBoard(&a,&b);
printBoard();
clearBoard();
//addBoard();
}
You can try this code (Slightly modifying your code)
#include <stdio.h>
#include <stdlib.h>
char *posArr[10][30];
void printInstructions(){
printf("Hello and welcome! Here you can configure your own breadboard\n");
printf("To do this you will use coordinates using this syntax:\n");
printf("width: 3\n");
printf("height: 5\n");
printf("After that a component will be choosen.\n");
printf("It would look like below:\n");
}
void printBoard(){
for (int i = 0; i < 10; i++)
{
printf("\n");
for (int j = 0; j < 30; j++)
{
printf("%s", posArr[i][j]);
}
}
}
void clearBoard(){
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 30; j++)
{
posArr[i][j] = ". ";
}
}
}
void buildBoard(int *width, int *height){
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 30; j++)
{
if (*height == i && *width == j){
posArr[i][j] = "¤ ";
}
else {
posArr[i][j] = ". ";
}
}
}
}
int main() {
printInstructions();
int a=3, b=5;
buildBoard(&a,&b);
printBoard();
clearBoard();
}
I'm a freshmen student and we have an activity in intro pro.. We were tasked to create a Christmas tree using a loop...
I have my code here:
#include<stdio.h>
int main ()
{
int rows,a,b,space;
clrscr();
printf("Enter a number of rows:");
scanf("%d",&rows);
space=rows-1
for(b=space;b>=1;b--)
{
for(a=rows;a>=1;a--)
space--;
printf("");
for(a=2*(rows-b)-1;a>=1;a--)
printf("*",a);
printf("\n");
space = space-1;
}
getche();
return 0;
}
This code was given to us by our professor... the program runs, but the output is wrong. Can you help me?
when i run this program, the output was like this:
*
***
*****
******
*******
You have to find a pattern. Say you want a tree with n rows. Last row is going to have 2n-1 stars. Row before it will have 2n-3 and so on. To print a row, first you print a number of spaces, then a number of stars. For last row, you print 0 spaces and 2n-1 stars. For row before it, you print 1 space and 2n-3 stars and so on.
for(int i = 0; i < n; i++)
{ for(int j = i + 1; j < n; j++)
printf(" ");
for(int j = 0; j <= 2*i; j++)
printf("*");
if(i < n - 1) puts("");
}
The Code is a little bit to messed up for me, but this should work:
#include<stdio.h>
int main() {
/*Variables*/
int rows, starNumber, spaceNumber;
int rowCount, spaceCount, starCount, treeTrunkCount, treeTrunkSpaceCount;
printf("Enter Rows:\n>");
scanf("%d",&rows);
for(rowCount = 1; rowCount <= rows; rowCount++) {
starNumber = rowCount * 2 - 1;
spaceNumber = rowCount + rows - starNumber;
for(spaceCount = 0; spaceCount < spaceNumber; spaceCount++)
printf(" ");
for(starCount = 0; starCount < starNumber; starCount++)
printf("%c",'*');
printf("\n");
}
for(treeTrunkCount = 0; treeTrunkCount < 3; treeTrunkCount++) {
for(treeTrunkSpaceCount = 0; treeTrunkSpaceCount < (rows * 2 + 1)/2; treeTrunkSpaceCount++)
printf(" ");
printf("%c\n",'*');
}
}
This is the simplest solution to your program..
#include <stdio.h>
int main()
{
int i=-1,j=0,rows;
printf("Enter Rows:\n");
scanf("%d",&rows);
while(j++<rows) // Moving pointer for the first '*'
{
printf(" ");
}
printf("*"); // This prints the first '*'
while(++i<rows)
{
for(j=-2;++j<rows-i;) // This loop will print Spaces before '*' on each row
printf(" ");
for(j=0;++j<2*i;) // This loop will print * on each row
{
printf("*");
}
printf("\n"); // This printf will take you to the next Line
}
}
This is the shortest and simplest solution for your question:
#include<stdio.h>
#include<conio.h>
void main(){
int count;
int i,j;
printf("enter the numbers of line");
scanf("%d",&count);
for(i=1;i<=count;i++){
for(j=1;j<=i;j++){
printf("*");
}
printf("\n");
}
getch();
}
You forgot a space between "".
for(a=rows;a>=1;a--)
space--;
printf("");
should be
for(a=rows;a>=1;a--)
space--;
printf(" ");
#include <stdio.h>
int main() {
int n = 50;
for (int i = 0; i <= n; ++i) {
for (int k = i; k < n; ++k)
printf(" ");
for (int j = 0; j < i; ++j)
printf("*");
for (int j = 1; j < i; ++j)
printf("*");
printf("\n");
}
for (int l = 1; l < n/2; ++l) {
for (int i = 1; i < n; ++i)
printf(" ");
printf("[|]\n");
}
return 0;
}
A simple tree can be made up with for loop, Christmas may need more symbol...
//Linux C program to print a tree
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
int pcenter(char *s) {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
int ct = w.ws_col;
int sl = strlen(s) / 2;
printf("%*s%*s\n", ct / 2 + sl, s, ct / 2 - sl, "");
return 0;
}
int ptree(char s, char t, int l, int r) {
int i;
for (i = 1; i <= l; i++) {
int j = 2 * i - 1;
char *p = malloc(j);
memset(p, s, j);
pcenter(p);
free(p);
}
for (i = 1; i <= r; i++) {
int j = 1;
char *p = malloc(j);
memset(p, t, j);
pcenter(p);
free(p);
}
return 0;
}
int main() {
// system("clear");
ptree('*', '|', 10, 5);
return 0;
}
#include<stdio.h>
main()
{
int n,i, j, space=1;
printf("Enter the number of rows: ");
scanf("%d",&n);
space=n-1;
for(i=1;i<=n;i++)
{
for(j=1;j<=space;j++)
{
printf(" ");
}
space--;
for(j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
for(i=1;i<=n-3;i++)
{
for(j=1;j<=10;j++)
{
printf(" ");
}
for(j=1;j<=1;j++)
{
printf("*");
}
for(j=1;j<=1;j++)
{
printf("*");
}
for(j=1;j<=1;j++)
{
printf("*");
}
printf("\n");
}
}
#include<stdio.h>
int main()
{
int i,j,k,l=1,a,b;
for(i=8;i>=0;i--)
{
for(j=0;j<=i;j++)
{
printf(" ");
}
k=0 ;
while(k<l)
{
printf("*");
k=k+1;
}
l=l+2;
printf("\n");
}
i=8;
for(b=0;b<=3;b++)
{
for(a=0;a<=i-1;a++)
{
printf(" ");
}
printf("***");
printf("\n");
}
}