Friday, 2 August 2013

Chapter 3 solutions problem[E][i]

Question-  Write a program to produce the following output: 
         1 
      2    3 
   4    5    6 
7    8    9    10

Solution-

Honestly speaking, I myself took help to solve this problem. nice problem. check this out.

#include<stdio.h>
#include<stdlib.h>

int main()
{
  int a,b,n=6;
  for(a=1;a<=10;a++)
  {
      if(a==1||a==2||a==4||a==7)
      {
      printf("\n");

      for(b=1;b<=n;b++)
      {
      printf(" ");
      n=n-1;
      }
  }
 printf("%d ",a);
}
return ();

}

6 comments:

  1. Your solution doesnt work

    ReplyDelete
  2. It's not working!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. A little correction

    #include
    #include
    main()
    {
    int a,b,s,p=1;
    clrscr ();
    for (a=1;a<=4;a++)
    { for (s=4;s>=a;s--){printf (" ");}
    for (b=1;b<=a;b++)
    {printf("%d ",p);
    p++;}
    printf("\n");
    }
    getch ();
    }

    ReplyDelete
  6. A little correction

    #include
    #include
    main()
    {
    int a,b,s,p=1;
    clrscr ();
    for (a=1;a<=4;a++)
    { for (s=4;s>=a;s--){printf (" ");}
    for (b=1;b<=a;b++)
    {printf("%d ",p);
    p++;}
    printf("\n");
    }
    getch ();
    }

    ReplyDelete