-->

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();
}

input and output programs in c++ (section 1)

Click the particular line to goto that page.
-------------------------------------------------------------

1. program to print hello world(1)

                                                                                solution
2. program to understand endl(2)
                                                                                solution
3. program to understand escape sequence(3)
                                                                                solution
4.program to understand white space(4)
                                                                               solution
5.program to use header file  with double quote(5)
                                                                                solution
6.program to understand input(6)
                                                                                 solution
7.program to know about cin to input data(7)
                                                                                 solution
8.program to understand string input in c++(8)
                                                                                 solution
9.program to print multiple string using single cout(9)
                                                                                 solution
10.program to understand character variable and constant(10)
                                                                                  solution
11.program to understand definition of variables(11)
                                                                                   solution
12.program to print character constatnt(12)
                                                                                   solution
13.program to understand setw() function(13)
                                                                                     solution
14.program to understand library function(14)
                                                                                      solution
15.program to understand type casting (data type conversion)(15)
                                                                                      solution
16. program to understand assignment operator(16)
                                                                                      solution

17.program to understand const identifier(p17)
                                                                                      solution
18.program to understand define directive or symbolic constant(18)
                                                                                       solution
19.program to understand arithmetic remainder operator(19)
                                                                                         solution
20.program to understand unary operator(prefix and postfix)(20)
                                                                                           solution
21. program to generate given table using single cout(21)
                                                                                          solution
22.program to generate following output(22)
                                                                                          solution
23. program to understand relational operator(23)
                                                                                          solution
24.program to understand logical operator(24)
                                                                                           solution
25.program to understand conditional operator(25)
                                                                                            solution
26.program to clear the screen using system(cls)(26)
                                                                                             solution
27.program to add two numbers without using namespace(27)
                                                                                              solution
28.program to print hello world without namespace(28)
                                                                                               solution