Social Icons

Featured Posts

Sunday, June 10, 2012

Write A C++ Program To Print A Hello World!

This is a typical C++ Hello World program. Here's the explanation what I have used in this program. In first two lines, I have used iostream and conio header's files of C++. In line no. 3, I have declared C++ main class that is void main(). After that I have used clrscr(); which is used to clear the screen of a C++ window. In line no. 6,7 and 8, I have used cout which is used to print a message. In C++, endl is used to end a line and getch(); is used to stop a screen of a C++ window so that a user can see what message got printed on window.

   1:  #include<iostream.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  clrscr();
   6:  cout<<"Hello World!";
   7:  cout<<endl;
   8:  cout<<"This is my first C++ program.";
   9:  getch();
  10:  }
 
Output of the program is :
Hello World! 
This is my first C++ program.

Write A C# Program To Print A Hello World!

In below example, I am only showing two Hello World messages. In line no. 18 and 24, I have used two buttons to perform the task. First, I have displayed the Hello World message in a Label control of C#.Net and in second I have used MessageBox.Show method to display the Hello World message in a pop up tiny window. Just copy and past this code in your C# page and hit F5 to run the program. This program in only intended for Visual Studio 2005 and upgraded versions.
Hello World


   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.ComponentModel;
   4:  using System.Data;
   5:  using System.Drawing;
   6:  using System.Text;
   7:  using System.Windows.Forms;
   8:   
   9:  namespace BlogWorld___HelloWorld
  10:  {
  11:      public partial class Form1 : Form
  12:      {
  13:          public Form1()
  14:          {
  15:              InitializeComponent();
  16:          }
  17:   
  18:          private void btnClickMe_Click(object sender, EventArgs e)
  19:          {
  20:              //To print a "Hello World" message on a Label
  21:              lblMsg.Text = "Hello World!";
  22:          }
  23:   
  24:          private void btnClickMsg_Click(object sender, EventArgs e)
  25:          {
  26:              //To print a "Hello World" message on Message Box
  27:              MessageBox.Show("Hello World!");
  28:          }
  29:      }
  30:  }
 

Sample text

Sample Text

Sample Text