Showing posts with label C Programs. Show all posts
Showing posts with label C Programs. Show all posts

Wednesday, 12 August 2015

C Program to print Data Type Size and Ranges


Program:

#include< stdio.h >
#include< conio.h >
#include< limits.h >
#include< float.h >
void main( )
{
            clrscr( ); // Clear the screen Contents
            printf("Integer data type:\n\tSize: %d\n\tRange: %d to %d", sizeof(int), INT_MIN, INT_MAX);
            printf("\nCharacter data type:\n\tSize: %d\n\tRange: %d to %d", sizeof(char), CHAR_MIN, CHAR_MAX);
            printf("\nFloat data type:\n\tSize: %d\n\tRange: %E to %E", sizeof(float), FLT_MIN, FLT_MAX);
            printf("\nDouble data type:\n\tSize: %d\n\tRange: %E to %E", sizeof(double), DBL_MIN, DBL_MAX);
}

Output:

Integer data type:
           Size: 2
           Range: -32768 to 32767
Character data type:
           Size: 1
           Range: -128 to 127
Float data type:
           Size: 4
           Range: 1.17549E - 38 to 3.402823E + 38
Double data type:
           Size: 8
           Range: 2.225074E - 308 to 1.797693E + 308



Monday, 18 May 2015

C Program for Conversion of Celsius Temperature to Fahrenheit Temperature

Objective: C Program for Conversion of temperature from Celsius to Fahrenheit

Analysis:

Input : Celsius Temperature

Output : Fahrenheit Temperature

Constraints : F = (C * 9/5)+32

Algorithm:

Step1. Start

Step2. Enter Celsius temperature value

Step3. Read Celsius temperature value

Step4. Fahrenheit Temperature = (C * 9/5)+32

Step5. Display Fahrenheit Temperature

Step6. Stop

Flow Chart:


Fig: Flow Chart for Conversion of Celsius to Fahrenheit


Implementation:

/* Conversion of Temperature from Celsius to Fahrenheit */

#include<stdio.h>
#include<conio.h>
void main( )
{
int c;
float f;
clrscr( ); //Clear Previous Screen Contents
printf("\nEnter Celsius temperature: ");
scanf("%d", &c);
f = (c * 9/5)+32;
printf("\nFahrenheit Temperature is %f",f);
getch( );
}

Compilation & Execution:
In linux:

Step1:

  gcc ctof.c

Step2:

  ./a.out

In Windows(Turbo C)

Step1:

ALT + F9( Compiling )





Step2:

F9( Linking )



Step3:

CTL + F9( Execution )




Output:

Enter Celsius temperature: 32

Fahrenheit Temperature is 93.2000


Source File: CtoF.C