9.13.2013

Even Number Pattern

Q. Write a C program to print the following even number pattern as:

 2
 2 4
 2 4 6
 2 4 6 8

Ans.

/*c program for even number pattern*/
#include<stdio.h>
int main()
{

 int r,c,p;
 for(r=1; r<=4; r++)
 {
   for(c=1,p=2; c<=r; c++,p=p+2)
     printf(" %d",p);
   printf("\n");
 }
 getch();
 return 0;
}

/************************************************************
The output of above program would be:
*************************************************************/

Output of even number pattern C program
Figure: Screen shot for even number pattern C program

2 comments:

  1. #include

    int main()
    {
    int num,i,j,k=2;

    printf("Enter last number:");
    scanf("%d",&num);

    for(i=2;i<=num;i=i+2)
    {
    for(j=2;j<=i;j=j+2)
    {
    printf(" %d",j);
    }
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  2. #include
    int main()
    {
    int i,j,n=4;
    for(i=0;i<n;i++)
    {
    for(j=1;j<=(i+1)*2;j++)
    if(j%2==0)
    printf("%d ",j);
    printf("\n");
    }
    }

    ReplyDelete