the output should be...

"1
  2
   3

     5
      6
       7
        8
         9
           Merry christmas"

using for loop..
here's my code !

</ #include<stdio.h>
   #include<conio.h>

   main()
  {
      int x;

     for(x=0;x<9;x++){
                       printf("\n %d ",x);

                       }

      getch();
      }


>

Edited 2 Years Ago by Dani: Formatting fixed

try like this(not tested but it will give you a hint):

for(x=1;x<=9;x++)
    {
        for(sp=1;sp<x;sp++)
        {
            printf(" ");
        }
        printf("%d\n",x);
    }
    printf("Merry chirstmas");

this should work.

Or if you want to use Cout to print instead

#include <iostream>
using namespace std;

for(int i =1, i<10,i++){
    cout<<"The current number is: "<<i<<endl;
}
cout<<"Merry xmas"<<endl;

have a look at the setw() from the lib iomanip.

for(int c=0;c<10;c++){
    cout << std::setw(c+5)<<c<<endl;
}
cout <<setw(25)<<"Merry xmas "; // simple alc (10*2)+5

//out put
   0
     1
      2
       3
        4
         5
          6
           7
            8
             9
              Merry xmas 

Edited 2 Years Ago by richieking

This article has been dead for over six months. Start a new discussion instead.