Search C Program

Number Pattern - 52

1
3 2
4 5 6
10 9 8 7
11 12 13 14 15

int main()
{
  int i,j,k,l;
  for(k=i=1;i<=5;i++)
  {
    l=k+i-1;
    for(j=1;j<=i;j++)
    {
      if(i%2==1)
        printf("%d ",k);
      else
        printf("%d ",l);
      k++;
      l--;
    }
    printf("\n");
  }
  return 0;
}


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


3 comments:

  1. Hey the output of your given code does not correspond to the expected output.
    Here is the my code that gives that output

    import java.util.Scanner;

    /* 1
    * 3 2
    * 4 5 6
    * 10 9 8 7
    * 11 12 13 14 15
    */
    public class UltaPulta
    {
    public static void main(String[] args)
    {
    int count = 1;
    Boolean direction = true;
    int reverse = 0;
    System.out.println("Enter number of rows to print :");
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for(int i = 1; i < n; i++)
    {
    if(direction == true)
    {
    for(int j = 1; j <= i; j++)
    {
    System.out.print(count+" ");
    count++;
    }
    direction = false;
    }
    else
    {
    reverse = count + i -1;
    for(int j = i; j >=1; j--)
    {
    System.out.print(reverse+" ");
    reverse--;
    count++;
    }
    direction = true;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  2. Alternate code for the above output ??

    ReplyDelete
  3. No the above logic code is giving correct outputoutput & is smaller

    ReplyDelete