example code from class

This commit is contained in:
Haldrup-tech 2024-08-29 15:15:33 -04:00
parent 2c490e7475
commit eb9255e54d
4 changed files with 69 additions and 0 deletions

32
csci218/Lect/ex3InClass.c Normal file
View File

@ -0,0 +1,32 @@
//use onlinegdb.com
// Example 3
#include <stdio.h>
int main(void) {
/*
// declare an int variable: age
int age;
//declare a string: userName
char userName[100];
//ask for the input,
//Good practice: prompt some hint
printf("Enter Name and Age (serperated by space): ");
scanf("%s %d", userName, &age);
//ask for name
//ask for age
//display the infomation
printf("Hello %s\nYou are %d years old.\n", userName, age);
//ask for more than one input
*/
char letter;
printf("Please give me a letter: ");
scanf("%c", &letter);
printf("your letter is: %c\n", letter);
return 0;
}

BIN
csci218/Lect/ex3InClass.out Executable file

Binary file not shown.

37
csci218/Lect/ex5InClass.c Normal file
View File

@ -0,0 +1,37 @@
//Example 5 in Class
#include <stdio.h>
int main(void) {
char nameOfSchool[] = "CofC"; //variable declaration and assignment
int numOfStudent = 10000; //variable declaration and assignment
/*i ncrease number of student by 1000 */
numOfStudent += 1000;
//using compound operators
//printf("After one year, the numer of students in Cofc is %d\n", numOfStudentCofC);
printf("After one year, the number of students in Cofc is %d\n\n", numOfStudent);
/* declare integer x, y, z */
int x, y, z;
x = 0;
y = 2;
z = 3;
/* using compound operators */
// x = x + 6;
// y = y / 5;
// z = z * 5;
x += 6;
y /= 5;
z *= 5;
//y = x++;
//int z = ++x;
//printf("x = %d, y = %d, z = %d , nameOfAccountHolder = %s \n", x, y, z, nameOfAccountHolder);
printf("x = %d\ny = %d\nz = %d\n", x, y, z);
return 0;
}

BIN
csci218/Lect/ex5InClass.out Executable file

Binary file not shown.