Download presentation
Presentation is loading. Please wait.
Published byMarshall Logan Modified over 9 years ago
1
First Program in C With Output
3
C Language Keywords
6
Variables In C
9
Initialize int value in declaration
11
Using a variable to store value
14
Meaningful variable name
16
Define three variables and use assignment operator to assign value int main() { int term; /* term used in two expressions */ int term_2; /* twice term */ int term_3; /* three times term */ term = 3 * 5; term_2 = 2 * term; term_3 = 3 * term; return (0); }
17
Use printf to output variable
19
Printing Variable Contents
22
Finding the limits
23
#include #include #include int main(void) { printf("Variables of type char store values from %d to %d", CHAR_MIN, CHAR_MAX); printf("\nVariables of type unsigned char store values from 0 to %u", UCHAR_MAX); printf("\nVariables of type short store values from %d to %d", SHRT_MIN, SHRT_MAX ); printf("\nVariables of type unsigned short store values from 0 to %u",USHRT_MAX); printf("\nVariables of type int store values from %d to %d", INT_MIN, INT_MAX); printf("\nVariables of type unsigned int store values from 0 to %u", UINT_MAX); printf("\nVariables of type long store values from %ld to %ld", LONG_MIN, LONG_MA X); printf("\nVariables of type unsigned long store values from 0 to %lu", ULONG_MAX); printf("\nVariables of type long long store values from %lld to %lld", LLONG_MIN, LLO NG_MAX);
24
printf("\nVariables of type unsigned long long store values from 0 to %llu", U LLONG_MAX); printf("\n\nThe size of the smallest non- zero value of type float is %.3e", FLT_MIN); printf("\nThe size of the largest value of type float is %.3e", FLT_MAX); printf("\nThe size of the smallest non- zero value of type double is %.3e", DBL_MIN); printf("\nThe size of the largest value of type double is %.3e", DBL_MAX); printf("\nThe size of the smallest non- zero value of type long double is %.3Le", LDBL_MIN); printf("\nThe size of the largest value of type long double is %.3Le\n", LDBL_ MAX); printf("\nVariables of type float provide %u decimal digits precision.", FLT_D IG); printf("\nVariables of type double provide %u decimal digits precision.", DBL _DIG); printf("\nVariables of type long double provide %u decimal digits precision.", LDBL_DIG); return 0; }
25
OUTPUT
27
Finding the size of a type
29
Scope of variables
30
value of i is 1 the value of i is 10 The Value of i is 1 The Value of i is 10
31
Inner variable shadows outer variable
33
Output
35
Declare global variables
37
Define and use Global variables
40
Local variable shadows global variable.
42
Static variable
44
Output
46
Static versus automatic variables
49
Output address and value
51
Using the & operator
54
Calculate an average using variable argument lists
58
Adding Comments
65
Indentation and Code Format
66
Without Indentation
67
With Indentation
68
Clarity
71
Header Files
72
IncludeHeader File
77
Newly Added Headers
83
External Reference
84
// Program in file A1.c #include void hell() { int i =60; printf("value o f i %d\n",i); }
85
// Program in file A2.c #include extern int i; void main() { int i =50; clrscr(); hell(); printf("value of i %d\n",i); }
86
output The value of variable i is 60
87
Data Types
91
Unsigned Variables
96
Reading Integer’s
97
Reading integer’s can be done through scanf void main(){ int i; scanf(“%d”,&i); printf(“i=%d”,i); }
98
#include int main() { printf( "%4d\n", 1 ); printf( "%4d\n", 12 ); printf( "%4d\n", 123 ); printf( "%4d\n", 1234 ); printf( "%4d\n\n", 12345 ); printf( "%4d\n", -1 ); printf( "%4d\n", -12 ); printf( "%4d\n", -123 ); printf( "%4d\n", -1234 ); printf( "%4d\n", -12345 ); return 0; }
99
#include int main() { printf( "%4d\n", 1 ); printf( "%4d\n", 12 ); printf( "%4d\n", 123 ); printf( "%4d\n", 1234 ); printf( "%4d\n\n", 12345 ); printf( "%4d\n", -1 ); printf( "%4d\n", -12 ); printf( "%4d\n", -123 ); printf( "%4d\n", -1234 ); printf( "%4d\n", -12345 ); return 0; }
102
Simple Int Calculation
104
Divide Integer
106
Sum the integers from 1 to a user- specified number
108
If both operands i1 and i2 are integers, the expression i1/i2 provides integer division
109
The atoi() function: read numeric values from the keyboard
113
Hexadecimal Numbers
115
Octal Numbers
122
Save Tab key into a char, you use an escape sequence
123
Output
125
#include int main() { clrscr(); // char tab='\x9C'; printf("**********"); printf("%%%\\Hello"); // printf("a%cb",tab); return 0; }
126
SOME % WILL BE DIMINISHED BECOZ OF “\\” output
127
#include int main() { clrscr(); // char tab='\x9C'; printf("**********"); printf("\?Hello\?"); // printf("a%cb",tab); return 0; }
130
Display the ASCII characters and their corresponding codes, from Code 32 on up to Code 127
132
Overflow in char and unsigned char data type Overflow means you are carrying out an operation such that the value either exceeds the maximum value or is less than the minimum value of the data type. (Definition from C & Data Structures by P.S. Deshpande and O.G. Kakde Charles River Media 2004)
134
Compare characters to characters in if statement #include void main() { char cResponse = '\0'; clrscr(); printf("\n\tAC Control Unit\n"); printf("\na\tTurn the AC on\n"); printf("b\tTurn the AC off\n"); printf("\nEnter your selection: "); scanf("%c", &cResponse);
135
Compare char variable in if statement
137
if (cResponse == 'a') printf("\nAC is now on\n"); if (cResponse == 'b') printf("\nAC is now off\n"); getch(); }
138
Using functions islower, isupper, tolower, toupper
141
Using functions isdigit, isalpha, isalnum, and isxdigit
144
Using functions isspace, iscntrl, ispunct, isprint, isgraph
147
Floats
148
C provides two main floating-point representations: float (single precision) and double (double precision ). A floating-point number has a fractional part and a biased exponent. Float occupies 4 bytes and double occupies 8 bytes.
149
Use the format %f for printing floating numbers
151
Float Basics
155
Define float constant value using Macro
156
Assignment of an integer expression to a floating-point variable. C will automatically perform the conversion from integer to floating point. A similar conversion is performed when a floating-point number is assigned to an integer.
158
output
159
To create precision with floating-point numbers
162
use the %E in printf() to display scientific-notation numbers
163
Printing floating-point numbers with floating-point conversion specifiers
164
Read float number and do a calculation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.