lab code and lecture code
This commit is contained in:
parent
a02d9995e5
commit
a61a49ca0f
40
csci218/Lect/ex6inClass.c
Normal file
40
csci218/Lect/ex6inClass.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* 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;
|
||||
}
|
||||
BIN
csci218/Lect/ex6inClass.out
Executable file
BIN
csci218/Lect/ex6inClass.out
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user