-->

Facebook

Jasper Roberts - Blog

Saturday, February 28, 2015

Switch...case Statement in C programming language.

In C programming language, sometimes we need to check multiple conditions. At that time we can you switch...case statement.

Syntax:
switch(choice)
{
case value1:
statement-1;
break;
case value2:
statement-2;
break;
case value3:
statement-3;
break;
case value4:
statement-4;
break;
.
.
.
.
.
case value-n:
statement-n;
break;

default:
default statement;
}


Example: A C Program to add, subtract, multiply, divide two values using switch...case statement.

Thursday, February 26, 2015

Write a C Program to convert Fahrenheit temperature to Centigrade.

// C Program to convert Fahrenheit temperature to Centigrade.

#include<stdio.h>
#include<conio.h>

void main()
{
       float fah, centi;
       clrscr();

       printf("Enter the temperature in Fahrenheit:");
       scanf("%f",&fah);

Write a C Program which explaining Shorthand Notations.

// C Program which explaining Shorthand Notations.

#include<conio.h>
#include<stdio.h>

void main()
{
         int i;
         clrscr();
         printf("Enter the value of i:");
         scanf("%d",&i);
       
         i += 5;
         printf("\n i = %d",i);

Type Casting in C Language

Type Casting
- When user needs the type conversion explicitly, then type casting is used in c programming language.
- Remember that type conversion is automatic while type casting is explicitly specified by the programmer in      program.
- Syntax:
              (type_name) expression;

- Where, type_name is the name of data type we want to convert the expression to.
- The converted value is used during evaluation of expression only.
- It does not change the basic data type of operand(s) of an expression.

- Example:
#include<stdio.h>               
#include<conio.h>

void main()
{
              int sum = 47;
              int number = 10;
              float average;

              clrscr();
              average = sum/number;       
              printf("average = sum/number = %f",average);              
              average = (float)sum/number;
              printf("\n average = (float)sum/number = %f",average);
              
              getch();
}