Home | Lab 1 | Lab 2 | Lab 3 | Lab 4 | Lab 5 | Lab 6 | Lab 7 | Lab 8 | Lab 9 | Lab 10 | Lab 11 | Lab 12

Linked at EntranceNepal.com, i-geek blog & Ekendra's Share World

Object: I. To perform Arithmetic Operations

Object: II. To convert Centigrade to Fahrenheit Scale

Background Theory:

Data type: Type is a fundamental concept in Standard C. When we declare a name, we give it a type. Each expression and sub expression that we write has a type. It is how the translator determines the properties of the types we specify within declarations, and how the program represents objects of various types. Integers and float are mathematical data types used in this sample C programming.

Following codes are used for respective data type
if integer      >>    int       >>    %d

if float           >>    float   >>    %f

if character >>    char    >>   %c

We use integer types to represent whole numbers, including zero or negative values. This has a vast emergence in C. The three sub-classifications of integer types are:

We use floating-point types to represent signed numbers that can have a fractional part. The range of values that we can represent with floating-point types is always much larger than the range we can represent with integer types, but the precision of floating-point values is limited. Three sorts of floating types:

• Float
• double
• long double

Code:

// Program to perform Arithmetic Operations //

# include <stdio.h>                                      /* header file*/

# include <conio.h>

void main()

{

int a, b;                                               /* variable declaration*/

float x;

clrscr();                                               /* to clear the screen*/

printf (“input a= “);                           /* library function*/

scanf (“%d”, &a);

printf (“input b= “);

scanf (“%d”, &b);

printf (“\n\t The sum= %d”, a+b);             /* output sum*/

printf (“\n\t The subtraction= %d”, a-b); /* output subtraction*/

printf (“\n\t The product= %d”, a*b);      /* output product*/

printf (“\n\t The reduction= %d”, a/b);   /* output reduction*/

x= a%b;

printf (“\n\t The remainder= %f”, x);        /* output remainder*/

printf (“\n \n \t\t Press any key to continue…”);

getch();                                              /* holds the output*/

}

// Program to convert Centigrade to Fahrenheit Scale//

# include <stdio.h>

# include <conio.h>

void main()

{

clrscr();

printf (“Enter centigrade value to convert to Fahrenheit scale= ”);

printf (“\n\t  Required Fahrenheit value = %d”, centigrade*9/5+32);

printf (“\n\n \t\t Press any key to continue…”);

getch();

}

Search yourself for more such codes

Home | Lab 1 | Lab 2 | Lab 3 | Lab 4 | Lab 5 | Lab 6 | Lab 7 | Lab 8 | Lab 9 | Lab 10 | Lab 11 | Lab 12