lcthw提交,做到了练习3,printf的输出格式

This commit is contained in:
Wang Bo Yang 2025-03-14 23:44:10 +08:00
parent 1ce1692d1b
commit 704504a2c1
16 changed files with 110 additions and 0 deletions

BIN
ex1/ex1 Executable file

Binary file not shown.

12
ex1/ex1.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
/* This is a comment. */
int main(int argc, char *argv[])
{
int distance = 100;
// this is also a comment
printf("You are %d miles away.\n", distance);
return 0;
}

BIN
ex1/ex1_copy Executable file

Binary file not shown.

12
ex1/ex1_copy.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
/* T is a comment. */
int main(int ac, char *gv[])
{
int distance = 100;
// this is also a comment
printf("You are %d mes away.\nGood morning!\nGood afternoon!\nGood night!\nGood evening!\nIt's time for dinner!\n", distance);
return 0;
}

1
ex1/vedio.txt Normal file
View File

@ -0,0 +1 @@
http://ewm.ptpress.com.cn:8085/preview?qrCode=qr2018001476&verified=true

6
ex2/Makefile Normal file
View File

@ -0,0 +1,6 @@
CFLAGS=-Wall -g
all: clean ex1
clean:
rm -f ex1

BIN
ex2/ex1 Executable file

Binary file not shown.

12
ex2/ex1.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
/* This is a comment. */
int main(int argc, char *argv[])
{
int distance = 100;
// this is also a comment
printf("You are %d miles away.\n", distance);
return 0;
}

BIN
ex2/ex1_copy Executable file

Binary file not shown.

12
ex2/ex1_copy.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
/* T is a comment. */
int main(int ac, char *gv[])
{
int distance = 100;
// this is also a comment
printf("You are %d mes away.\nGood morning!\nGood afternoon!\nGood night!\nGood evening!\nIt's time for dinner!\n", distance);
return 0;
}

1
ex2/vedio.txt Normal file
View File

@ -0,0 +1 @@
http://ewm.ptpress.com.cn:8085/preview?qrCode=qr2018001476&verified=true

BIN
ex3/ex3 Executable file

Binary file not shown.

12
ex3/ex3.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
int main(void)
{
int age = 10;
int height = 72;
printf("I am %d years old.\n", age);
printf("I am %d inches tall.\n", height);
return 0;
}

BIN
ex3/unsignedInt Executable file

Binary file not shown.

31
ex3/unsignedInt.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
int main ( void )
{
int smallInt = 12;
int largeInt = (1024*1024*3)+(1024*2)+512+128+64+32+16+8+4+2+1;
int negativeInt = -smallInt;
unsigned anUnsigned = 130;
// the other code snippets go here.
printf( " Unsigned Printf \n" );
printf( " Base Base-8 Base-10 Base-16 BASE-16\n" );
printf( " Name octal unsigned hexadeximal HEXIDECIMAL\n" );
printf( " Specifier %%12o %%12u %%12x %%12X \n" );
printf( " [%12o] [%12u] [%12x] [%12X]\n" ,
smallInt , smallInt, smallInt, smallInt );
printf( " [%12o] [%12u] [%12x] [%12X]\n\n" ,
largeInt , largeInt , largeInt , largeInt );
printf( " [%12o] [%12u] [%12x] [%12X]\n\n" ,
anUnsigned , anUnsigned , anUnsigned , anUnsigned );
printf( " Specifier %%#o %%#u %%#x %%#X\n" );
printf( " [%#12o] [%12u] [%#12x] [%#12X]\n" ,
smallInt , smallInt , smallInt , smallInt );
printf( " [%#12o] [%12u] [%#12x] [%#12X]\n" ,
largeInt , largeInt, largeInt , largeInt );
printf( " [%#12o] [%12u] [%#12x] [%#12X]\n\n" ,
anUnsigned , anUnsigned , anUnsigned , anUnsigned );
return 0;
}

11
ex3/unsignedInt_copy.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
int main ( void )
{
int smallInt = 12;
int largeInt = (1024*1024*3)+(1024*2)+512+128+64+32+16+8+4+2+1;
int negativeInt = -smallInt;
unsigned anUnsigned = 130;
// the other code snippets go here.
}