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

1 comment:

  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