0% found this document useful (0 votes)
4 views

5C Data Types Examples_112359

The document provides an example of using different C data types to calculate the total cost of items. It includes code that defines variables for the number of items, cost per item, total cost, and currency, and demonstrates how to print these values. The example illustrates basic C programming concepts such as variable declaration and output formatting.

Uploaded by

darrylyann5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

5C Data Types Examples_112359

The document provides an example of using different C data types to calculate the total cost of items. It includes code that defines variables for the number of items, cost per item, total cost, and currency, and demonstrates how to print these values. The example illustrates basic C programming concepts such as variable declaration and output formatting.

Uploaded by

darrylyann5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

C Data Types Examples

Real-Life Example
Here's a real-life example of using different data types, to calculate and
output the total cost of a number of items:

Example
// Create variables of different data types
int items = 50;
float cost_per_item = 9.99;
float total_cost = items * cost_per_item;
char currency = '$';

// Print variables
printf("Number of items: %d\n", items);
printf("Cost per item: %.2f %c\n", cost_per_item, currency);
printf("Total cost = %.2f %c\n", total_cost, currency);

#include <stdio.h>

int main() {
// Create variables of different data types
int items = 50;
float cost_per_item = 9.99;
float total_cost = items * cost_per_item;
char currency = '$';

// Print variables
printf("Number of items: %d\n", items);
printf("Cost per item: %.2f %c\n", cost_per_item, currency);
printf("Total cost = %.2f %c\n", total_cost, currency);

return 0;
}

You might also like