-->

C program to print box number pattern with zero in center


/**
 * C program to print box number pattern with zero in center
11011
11011
00000
11011
11011 

*/

#include <stdio.h>
#include<conio.h>
void main()
{
    int rows, cols, i, j;
    int centerRow, centerCol;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    centerRow = (rows+1) / 2;
    centerCol = (cols+1) / 2;

    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=cols; j++)
        {
            // Print 0 for central rows or columns
            if(centerCol == j || centerRow == i)
            {
                printf("0");
            }
            else if((cols%2 == 0 && centerCol+1 == j) || (rows%2 == 0 && centerRow+1 == i))
            {
                // Print an extra 0 for even rows or columns
                printf("0");
            }
            else
            {
                printf("1");
            }
        }

        printf("\n");
    }

    getch();
}

C program to print box number pattern with cross center


/**
 * C program to print box number pattern with cross center
10001
01010
00100
01010
10001 


*/

#include <stdio.h>
#include<conio.h>
void main()
{
    int rows, cols, i, j;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=cols; j++)
        {
            if(i == j || (j == (cols+1) - i))
            {
                printf("1");
            }
            else
            {
                printf("0");
            }
        }

        printf("\n");
    }

    getch();
}

C program to print number pattern


/**
 * C program to print number pattern
12345
23455
34555
45555
55555 

*/

#include <stdio.h>
 #include<conio.h>
void main()
{
    int rows, cols, i, j;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    for(i=1; i<=rows; i++)
    {
        for(j=i; j<=cols; j++)
        {
            printf("%d", j);
        }

        for(j=i; j>1; j--)
        {
            printf("%d", cols);
        }

        printf("\n");
    }

    getch();
}
                                                                source : codeforwin.org

C program to print hollow pyramid star pattern


/**
 * C program to print hollow pyramid  star pattern
                     *
                 *       *
             *                *
         *                       *
      *                              *
    *  *   *   *   *  *  *  *   *

*/

#include <stdio.h>
#include<conio.h> 
void main()
{
    int i, j, rows;

    /* Input rows to print from user */
    printf("Enter number of rows : ");
    scanf("%d", &rows);

    for(i=1; i<=rows; i++)
    {
        /* Print trailing spaces */
        for(j=i; j<rows; j++)
        {
            printf(" ");
        }

        /* Print hollow pyramid */
        for(j=1; j<=(2*i-1); j++)
        {
            /*
             * Print star for last row (i==rows),
             * first column(j==1) and for
             * last column (j==(2*i-1)).
             */
            if(i==rows || j==1 || j==(2*i-1))
            {
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }

        /* Move to next line */
        printf("\n");
    }

    getch();
}

C program to print hollow right triangle star pattern


/**
 * C program to print hollow right triangle star pattern

*
*   *
*      *
*         *
*            *
*               *
*                   *
*   *   *   *      *

*/

#include <stdio.h>
#include<conio.h>
void main()
{
    int i, j, rows;

    /* Input rows from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);

    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=i; j++)
        {
            /*
             * Print star for first column(j==1),
             * last column(j==i) or last row(i==rows).
             */
            if(j==1 || j==i || i==rows)
            {
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }

        printf("\n");
    }

    getch();
}

source: codeforwin.org

C program to print hollow pyramid star pattern

/**
 * C program to print hollow pyramid  star pattern

                *
             *     *
           *           *
        *                 *
      *                      *
 
*/

#include <stdio.h>
#include<conio.h>
void main()
{
    int i, j, rows;

    /* Input rows to print from user */
    printf("Enter number of rows : ");
    scanf("%d", &rows);

    for(i=1; i<=rows; i++)
    {
        /* Print trailing spaces */
        for(j=i; j<rows; j++)
        {
            printf(" ");
        }

        /* Print hollow pyramid */
        for(j=1; j<=(2*i-1); j++)
        {
            /*
             * Print star for last row (i==rows),
             * first column(j==1) and for
             * last column (j==(2*i-1)).
             */
            if(j==1 || j==(2*i-1))
            {
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }

        /* Move to next line */
        printf("\n");
    }

    getch();

}
source: codeforwin.org

program to convert kilometer to meter

// program to convert kilometer to meter
#include<stdio.h>
#include<conio.h>
void main()
{
float kilometer;
float meter;
printf(“enter value of kilometer\n”);
scanf(“%f”,&kilometer);
meter=kilometer*1000;
printf(“the area is=%f\n”,meter);
getch();
}