编程札记

计

计算机编程 逻辑运算符

计算机编程 逻辑运算符 #include <stdio.h> int main() { int a = 1; int b = 0; if ( a && b ) { printf("This will never print because condition is false\n" ); } if ( a || b ) { printf("This will be printed print because condition is true\n" ); } if ( !(a && b) ) { printf("This will be printed print because condition is true\n" ); } }

阅读全文 ↗
计

计算机编程 关系运算符

计算机编程 关系运算符 #include <stdio.h> int main() { int a, b; a = 10; b = 20; /* Here we check whether a is equal to 10 or not */ if( a == 10 ) { /* if a is equal to 10 then this body will be executed */ printf( "a is equal to 10\n"); } /* Here we check whether b is equal to 10 or not */ if( b == 10 ) { /* if b is equal to 10 then this body will be executed */ printf( "b is equal to 10\n"); } /* Here we check if a is less b than or not */ if( a < b ) { /* if a is less than b then this body will be executed */ printf( "a is less than b\n"); } /* Here we check whether a and b are not equal */ if( a != b ) { /* if a is not equal to b then this body will be executed */ printf( "a is not equal to b\n"); } }

阅读全文 ↗
计

计算机编程数学运算符

计算机编程数学运算符 #include <stdio.h> int main() { int a, b, c; a = 10; b = 20; c = a + b; printf( "Value of c = %d\n", c); c = a - b; printf( "Value of c = %d\n", c); c = a * b; printf( "Value of c = %d\n", c); c = b / a; printf( "Value of c = %d\n", c); c = b % a; printf( "Value of c = %d\n", c); }

阅读全文 ↗
计

计算机编程分号

计算机编程分号 #include <stdio.h> int main() { /* printf() function to write Hello, World! */ printf( "Hello, World!\n" ); printf( "Hello, World!" ); }

阅读全文 ↗
C

C库函数 rename()

C库函数 rename() #include <stdio.h> int main () { int ret; char oldname[] = "file.txt"; char newname[] = "newfile.txt"; ret = rename(oldname, newname); if(ret == 0) { printf("File renamed successfully"); } else { printf("Error: unable to rename the file"); } return(0); }

阅读全文 ↗