Presentation is loading. Please wait.

Presentation is loading. Please wait.

First Program in C With Output. C Language Keywords.

Similar presentations


Presentation on theme: "First Program in C With Output. C Language Keywords."— Presentation transcript:

1 First Program in C With Output

2

3 C Language Keywords

4

5

6 Variables In C

7

8

9 Initialize int value in declaration

10

11 Using a variable to store value

12

13

14 Meaningful variable name

15

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

18

19 Printing Variable Contents

20

21

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

26

27 Finding the size of a type

28

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

32

33 Output

34

35 Declare global variables

36

37 Define and use Global variables

38

39

40 Local variable shadows global variable.

41

42 Static variable

43

44 Output

45

46 Static versus automatic variables

47

48

49 Output address and value

50

51 Using the & operator

52

53

54 Calculate an average using variable argument lists

55

56

57

58 Adding Comments

59

60

61

62

63

64

65 Indentation and Code Format

66 Without Indentation

67 With Indentation

68 Clarity

69

70

71 Header Files

72 IncludeHeader File

73

74

75

76

77 Newly Added Headers

78

79

80

81

82

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

88

89

90

91 Unsigned Variables

92

93

94

95

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; }

100

101

102 Simple Int Calculation

103

104 Divide Integer

105

106 Sum the integers from 1 to a user- specified number

107

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

110

111

112

113 Hexadecimal Numbers

114

115 Octal Numbers

116

117

118

119

120

121

122 Save Tab key into a char, you use an escape sequence

123 Output

124

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; }

128

129

130 Display the ASCII characters and their corresponding codes, from Code 32 on up to Code 127

131

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)

133

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

136

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

139

140

141 Using functions isdigit, isalpha, isalnum, and isxdigit

142

143

144 Using functions isspace, iscntrl, ispunct, isprint, isgraph

145

146

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

150

151 Float Basics

152

153

154

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.

157

158 output

159 To create precision with floating-point numbers

160

161

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

165


Download ppt "First Program in C With Output. C Language Keywords."

Similar presentations


Ads by Google