Sep 7, 2015

BASIC 'C' programming Example

  • To display "Hello World"

#include <stdio.h>
#include <conio.h>
int main( )
{
  printf ("Hello world \n");
  return ( 0 ) ;
}



  • To Add two numbers

#include<stdio.h>
int main( )
{
   int a, b, c;
   printf("Enter two numbers to add \n");
   scanf("%d%d",&a,&b);
   c = a + b;
   printf("Sum of entered numbers = %d\n",c);
   return (0);
}

  • To decide whether a number is odd or even

#include <stdio.h>
int main( )
{
   int n;
   printf ("Enter an integer \n");
   scanf ("%d", &n);
   if (n%2 == 0)
      printf("Even\n");
   else
      printf("Odd\n");
   return (0);
}

- For any examples required you can comment and the example will be provided. 




No comments:

Post a Comment