0% found this document useful (0 votes)
23 views4 pages

Datatype

The document contains multiple C programs demonstrating various concepts, including printing the size of different data types, multiplying floating point numbers, displaying ASCII values, performing basic arithmetic operations, and converting temperatures. Each program is self-contained, showcasing specific functionalities such as area calculation, power computation, and boolean data type usage. The examples serve as practical applications of C programming fundamentals.

Uploaded by

Swatilagna sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Datatype

The document contains multiple C programs demonstrating various concepts, including printing the size of different data types, multiplying floating point numbers, displaying ASCII values, performing basic arithmetic operations, and converting temperatures. Each program is self-contained, showcasing specific functionalities such as area calculation, power computation, and boolean data type usage. The examples serve as practical applications of C programming fundamentals.

Uploaded by

Swatilagna sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

(1) C Program to print size of different data type in C.

#include <stdio.h>

int main()
{
int size_of_int = sizeof(int);
int size_of_char = sizeof(char);
int size_of_float = sizeof(float);
int size_of_double = sizeof(double);

printf("The size of int data type : %d\n", size_of_int);


printf("The size of char data type : %d\n",
size_of_char);
printf("The size of float data type : %d\n",
size_of_float);
printf("The size of double data type : %d",
size_of_double);

return 0;
}

(2) C program to multiply two floating point numbers

#include <stdio.h>

// Function to multiply floating point


// numbers
float multiply(float a, float b)
{
return a * b;
}

// Driver code
int main()
{
float A = 2.12, B = 3.88, product;

// Calling product function


product = multiply(A, B);

// Displaying result up to 3 decimal places.


printf("Product of entered numbers is:%.3f", product);

return 0;
}

(3)C program to print ASCII Value of Character

#include <stdio.h>

int main() {
char character = 'A';

// Display ASCII value of the character


printf("The ASCII value of %c is %d\n", character, character);

return 0;
}
(4)C program to demonstrate the use of different data types:

#include <stdio.h>

int main() {
// Declaration of variables with different data types
int integerVar = 100; // Integer data type
float floatVar = 25.76; // Float data type
char charVar = 'A'; // Character data type
double doubleVar = 12345.6789; // Double data type
short shortVar = 500; // Short integer data type
long longVar = 1234567890; // Long integer data type

// Displaying the values of the variables


printf("Integer value: %d\n", integerVar);
printf("Float value: %f\n", floatVar);
printf("Character value: %c\n", charVar);
printf("Double value: %lf\n", doubleVar);
printf("Short value: %d\n", shortVar);
printf("Long value: %ld\n", longVar);

return 0;
}

(5)WAP for Basic Arithmetic Operations with Different Data Types

#include <stdio.h>

int main() {
int num1 = 10, num2 = 5;
float num3 = 10.5, num4 = 5.5;
double num5 = 20.25, num6 = 10.75;

// Integer arithmetic
printf("Integer addition: %d + %d = %d\n", num1, num2, num1 + num2);
printf("Integer division: %d / %d = %d\n", num1, num2, num1 / num2);

// Float arithmetic
printf("Float addition: %.2f + %.2f = %.2f\n", num3, num4, num3 + num4);
printf("Float division: %.2f / %.2f = %.2f\n", num3, num4, num3 / num4);

// Double arithmetic
printf("Double addition: %.2lf + %.2lf = %.2lf\n", num5, num6, num5 + num6);
printf("Double division: %.2lf / %.2lf = %.2lf\n", num5, num6, num5 / num6);

return 0;
}

(6)WAP to check Boolean Data Type with stdbool.h

#include <stdio.h>
#include <stdbool.h> // For bool, true, false

int main() {
bool isRaining = true;
bool isSunny = false;

// Printing boolean values


printf("Is it raining? %s\n", isRaining ? "Yes" : "No");
printf("Is it sunny? %s\n", isSunny ? "Yes" : "No");

return 0;
}
(7)C program calculates the area of a circle using a float data type for precision

#include <stdio.h>

int main() {
float radius, area;
const float PI = 3.14159;

// Input radius
printf("Enter the radius of the circle: ");
scanf("%f", &radius);

// Calculate area
area = PI * radius * radius;

// Display area
printf("The area of the circle is: %.2f\n", area);

return 0;
}

(8 )Calculate the Power of a Number Using pow() (with double)

#include <stdio.h>
#include <math.h>

int main() {
double base, exponent, result;

// Input base and exponent


printf("Enter base: ");
scanf("%lf", &base);
printf("Enter exponent: ");
scanf("%lf", &exponent);

// Calculate power
result = pow(base, exponent);

// Display result
printf("%.2lf raised to the power of %.2lf = %.2lf\n", base, exponent, result);

return 0;
}

(9)Temperature Conversion (Celsius to Fahrenheit)

#include <stdio.h>

int main() {
float celsius, fahrenheit;

// Input temperature in Celsius


printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
// Convert to Fahrenheit
fahrenheit = (celsius * 9 / 5) + 32;

// Display the temperature in Fahrenheit


printf("%.2f Celsius = %.2f Fahrenheit\n", celsius, fahrenheit);

return 0;
}

You might also like