Saturday, 18 February 2017

c program the division operation

Program :

#include<stdio.h>
#include<conio.h>
int main()
{
     int x,y;
     int result1,result2;
     printf("\n Enter the dividend : ");
     scanf("%d",&x);
     printf("\n Enter the divisor: ");
     scanf("%d",&y);
     result1 = x/y;          
     result2 = x%y;        
     printf("\n The Quotient is: %d ",result1);
     printf("\n The Remainder is: %d ",result2);
     getch();
     return 0;

}


Output ;




Sum of Series 1+2+3+..+n

Program :

#include<stdio.h>
void main()
{
  int sum=0,i,n;
  printf("\n>>> C Program to print Sum of Series 1+2+3+..+n <<<\n");
  printf("\n Enter the number of terms:");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
      sum+=i;
  }
  printf("\n Sum of series upto %d is :%d \n\n",n,sum);


}


Output :



Friday, 17 February 2017

C in size operator

Program :

#include<stdio.h>
void main()
{
  printf("\n size of int is: %d",sizeof(int));
  printf("\n size of float is: %d",sizeof(float));
  printf("\n size of double is: %d",sizeof(double));
  printf("\n size of char is: %d",sizeof(char));

}

Note: In borland C or Turbo C compilers size of int is 2.

Output :


c program for pre decrement and post decrement

Program :

#include<stdio.h>
main()
{
 int i=20,j;

j=i--;          /* j value 20 , i value 21*/

 /*post decrement*/

 printf("\n After post-decrement: j value: %d , i value:%d \n",j,i);

 j=--i;         /* j value 22, i value 22*/
  
/*pre-decrement*/

printf("\n After pre-decrement: j value: %d, i value:%d \n",j,i);

 return(0);

}

Output :


c program for pre increment and post increment

Program :

#include<stdio.h>
main()
{
 int i=10,j;

 j=i++; /* j value 10 , i value 11*/

 /*post increment*/

 printf("\n After post-increment: j value:  %d , i value: %d \n",j,i);

 j=++i; /* j value 12, i value 12*/

 /*pre-increment*/

 printf("\n After pre-increment: j value: %d, i value : %d \n",j,i);

 return(0);
}

Output :


c program to implement simple if-else in c

Syantax :

if(condition)
{
 statement1;
 statement2;
 . 
 .
 .
 statement n;
}
else
{
 statement1;
 statement2;
 . 
 .
 .
 statement n;
}

Program :

#include<stdio.h>
void main()
{
    int num;
    printf(" <<< c program to implement simple if-else >>>\n\n");
    printf("\n Enter the number: ");
    scanf("%d",&num);
    if(num%2==0) 
    {
        printf("\n Entered number is Even Number \n");
    }
    else
    {
      printf("\n Entered number is Odd Number \n\n");
    }
}

Output :


Simple if statement

Syantax:

if(condition)
{
 statement1;
 statement2;
 . 
 .
 .
 statement n;

}

Program :

#include<stdio.h>
void main()
{
    int age;
    printf(" >>> c program to implement simple if<<< \n\n");
    printf("\n Enter the age of the person: ");
    scanf("%d",&age);
    if(age>=18)
    {
        printf("\n Eligible for Licence \n");
    }
    printf("\n program ends \n\n");
}



Output: