41 lines
924 B
C
41 lines
924 B
C
/* simple statement example ex6InClass.c
|
|
By Dr. Xu
|
|
This program is for explaining the building blocks of C
|
|
*/
|
|
|
|
# include <stdio.h> //For accessing the standard library functions
|
|
# include <math.h>
|
|
|
|
int main() {
|
|
/* literals: 5, 6, 3, 3.14, "James", '!'
|
|
Variables: a, b, c, name, punc
|
|
Constant: PI
|
|
Expressions: a + b * 3, a + 6
|
|
function: printf()
|
|
datatype: int, char, float
|
|
*/
|
|
|
|
//variable declaration ;
|
|
// variable assignment
|
|
int a, b; // variable assignment
|
|
//variable declaration and initialization
|
|
a = 5;
|
|
b = a + 5;
|
|
float c = 1.5;
|
|
|
|
const float PI = 3.1415926;
|
|
|
|
c = PI * pow(b, 2.0);
|
|
|
|
|
|
printf("a = %d\nb = %d\nc = %.3f\nPI = %.3f\n", a, b, c, PI);
|
|
|
|
char stName[] = "James";
|
|
char punc = '!';
|
|
|
|
printf("Good Bye, %s%c\n", stName, punc);
|
|
|
|
//printf("Good bye, %s %c \n", name, punc);
|
|
return 0;
|
|
}
|