-->

Facebook

Jasper Roberts - Blog

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();
}

Operators in C Programming Language

- C Language supports rich set of operators.
- Operators are used in doing various operations.
- The Operators can be divided into different categories.

- These Operators are:
1. Arithmetic Operators.
2. Relational Operators.
3. Logical Operators.
4. Assignment Operator.
5. Conditional Operators.
6. Increment and Decrements Operators.
7. Bit wise Operator.
8. Special Operators.

1. Arithmetic Operators.
         - In C programming, Arithmetic Operators are used in performing mathematical expressions.
         - The c language does not provide the operator for exponentiation.  
         - C language supports following Arithmetic Operators:
            Operator Name                    Meaning
                   +                                  Add
                   -                                   Subtract
                   *                                   Multiply
                   /                                    Divide
                   %                                  Modulo Division.
          - The operator + and - can be used as unary operator also.
          - Except % operator all Arithmetic Operators can be used with any type of numeric operands, while
             % operator can only be used with integer data type only.