Header Ads Widget

Responsive Advertisement

C Hello world

C programming language: If you want to learn C language easily you need to start making programs/codes. As you may already know that to develop programs you need a text editor and a compiler to translate a source program into machine code which can be executed directly on a machine.So the best programming platform for you to start practicing programs are :  For PC - Code blocks, Dev C++ or For Android - turboCdroid

How to write a hello world in C language? 
This could be your first C program. Let's have a look at the program first.

SIMPLE DISPLAYING

#include <stdio.h>  //Start of the program with header files  is must.

int main()                 
{
  printf("HELLO WORLD\n");  
//Display function printf() is used.  
  return 0;  
//returns the result.
}

  •  <stdio.h>= header file contains the declaration of the function.
  •  printf() = It is library function used to display text on the screen.
  •  '\n' =  Places the cursor at the beginning of the next line .         
OUTPUT :

HELLO WORLD     


DISPLAY using character variables


#include <stdio.h>  //Start of the program

int main()
{
  char a,b,c,d,e,f,g;   
// Declaring variables 

   a = 'H'; // assigning values to the variables.

   b = 'E';

   c = 'L';

   d = 'O' 

   e = 'W';

   f = 'R';

   g = 'D'; // assigning values to the variables.

  printf("%c%c%c%c%c%c%c%c%c%c", a, b, c, c, d, e, d, f, c, g);  //Displaying the output

  return 0; // returns result

}

 OUTPUT :

HELLOWORLD            


 DISPLAY using string (a character array).

#include <stdio.h> //Start of the program

int main()
{
  char s1[ ] = "HELLO WORLD\t"; 
  char s2[] = {'H','e','l','l','o','w','o','r','l','d'}; 
//Declaration of variables and assigning value to them.

  printf("%s %s", s1, s2);//Displaying the output.

return 0; //returns result.

}

Output:

HELLO WORLD        Helloworld      

  • \t = places the cursor 8 steps ahead.

Post a Comment

0 Comments