Search C Program

Number Pattern - 42

11111
1   1
1   1
1   1
11111 

#include<stdio.h>

int main()
{
    int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        {
            if(j==5 || j==1 || i==1 || i==5)
                printf("1");
            else
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}


Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C


2 comments:

  1. #include
    int main(){
    int i,j;
    for(i=1;i<=5;i++){
    for(j=1;j<=5;j++){

    if(i==1||i==5){
    printf("1");
    }
    else if(i==2||i==3||i==4){
    if(j==1||j==5){
    printf("1");
    }
    else{
    printf(" ");
    }

    }

    }
    printf("\n");

    }

    }

    ReplyDelete
  2. #include

    int main()
    {
    int r,i,j;

    printf("Enter the no. of rows : ");
    scanf("%d",&r);

    for(i=1;i<=r;i++)
    {
    printf("1");

    for(j=1;j<=r-2;j++)
    {
    if(i==1||i==r)
    {
    printf("1");
    }
    else
    {
    printf(" ");
    }

    }

    printf("1\n");
    }

    return 0;
    }

    ReplyDelete