Skip to main content

Posts

ads by adstra

A-ads

Learn C Language

    

Examples of C programme

  C programming examples with output Example 1 - C hello world program /** My first C program */ #include <stdio.h>   int  main ( ) {    printf ( "Hello World \n " ) ;    return   0 ; } Output of program: "Hello World" Example 2 - C program to get input from a user using scanf #include <stdio.h> int  main ( ) {    int  x ;    printf ( "Input an integer \n " ) ;    scanf ( "%d" ,   & x ) ;   // %d is used for an integer    printf ( "The integer is: %d \n " ,  x ) ;    return   0 ; } Output: Input an integer 7897 The integer is: 7897 Example 3 - using if else control instructions #include <stdio.h> int  main ( ) {    int  n ;    printf ( "Enter a number \n " ) ;    scanf ( "%d" ,   & n ) ;    if   ( n  >   0 )      printf ( "Greater than zero. \n " ) ;    else      printf ( "Less than or equal to zero. \n " ) ;    return   0 ; } Output: Enter a number -45 Less than or eq