Sunday, 20 January 2013

The First C Program in Three Different ways



“Hello World program”

C Hello World Program: - C programming language code to print Hello World. This program print Hello World, printf function is used to display text screen, ‘\n’ places cursor on the beginning of next line, stdio.h header file contains declaration of printf function, getch is used to hold screen. The code will work on all operating systems may be its Windows, Linux, Mac or any other and compilers. To learn a programming language you must start writing programs in it and may be your first C code while learning programming.

Example:
1 – C Hello World

#include<stdio.h>
int main()
{
     printf(“Hello World”);
     return 0;
}

2 – Hello World program in C

      We may store “Hello World” in a character array and then print it.

#include<stdio.h>
int main()
{
     char string[] = “Hello World”;
     printf(‘%s\n”,string);
     return 0;
}

3 – Print text “Hello World” Program in C

/* To Print any Text */
#include<stdio.h>
void main()
{
     printf(“Hello World”);
     getch();
}

OUTPUT
Hello World

1 comment:

  1. #include

    I prefer this one

    void main(void)
    {
    char string[] = "Hello World";
    while(*string != 0)
    {
    putchar(*string++);
    }
    putchar('\n');
    }

    ReplyDelete