![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C Programming
kerin_lu
这个作者很懒,什么都没留下…
展开
-
The Flow Chart of Running C Program
原创 2013-09-17 22:28:46 · 701 阅读 · 0 评论 -
Find all the prime number between 1 and 100
/* Find all the prime number between 1 and 100 */#include#includeint main(){int i,n,j = 0;for (n = 2; n <= 100; ++n){bool isPrime = true;for (i = 2; i {if (n % i原创 2013-09-17 22:32:07 · 1221 阅读 · 0 评论 -
Check whether two input intergers are the same without using comparison operator
//Check wheter two input intergers are the same without using the #includeint main(){ int a,b; printf("Please input two intergers:\n"); scanf("%d%d",&a,&b); if ((a^b) == 0) {原创 2014-07-18 09:26:19 · 639 阅读 · 0 评论 -
Telegram Encoding and Decoding
// Telegram Encoding#includevoid main(){ char c; while((c = getchar()) != '\n') { if((c >= 'a' && c = 'A' && c <= 'Z')) { c = c + 4; if ((c > 'z') || (c < 'z' && c <= 'Z'-4)) c =原创 2013-09-18 17:28:51 · 792 阅读 · 0 评论 -
Exchange the numbers of row and array of a two-dimensional array, and form a new two-dimensional ar
// Exchange the numbers of row and array of a two-dimensional array, and form a new two-dimensional array#includevoid main(){ int a[2][3]={{1,2,3},{4,5,6}}; int b[3][2],i,j; printf("arrary a:\n"原创 2013-09-17 21:16:47 · 756 阅读 · 0 评论 -
Bubble Sort
// Bubble Sort#includeint main(void){ int a[10]; int i,j,t; printf("Pls input 10 numbers:\n"); for (i = 0; i < 10; i++) scanf("%d",&a[i]); printf("\n"); for (j = 0; j < 9; j++) { for (i原创 2013-09-25 19:17:39 · 448 阅读 · 0 评论 -
Two Minor Questions
Question 1:We would like to assign rooms for students. Assume there are x students, each room could accommodate 6 students. Use one formula to find out how many rooms we needed in total.Ans原创 2013-09-17 22:35:41 · 647 阅读 · 0 评论 -
C语言main()函数详解
Source: http://c.biancheng.net/cpp/html/725.htmlC的设计原则是把函数作为程序的构成模块。main()函数称之为主函数,一个C程序总是从main()函数开始执行的。 一、main()函数的形式在C99 标准中,只有以下两种定义方式是正确的:int main( void ) /* 无参数形式 */{ ... return 0;}i转载 2015-05-22 21:22:59 · 1135 阅读 · 0 评论 -
Print the isosceles triangle using symbol "*"
Key Points:1) Use double "for" cycle2) Calculate the number of spaces before symbol "*"原创 2014-08-06 18:53:17 · 687 阅读 · 0 评论 -
Reverse an input character string
//Inverse an input charater string#includeint main(){ char a[50]; int l; char *p; printf("Please input a character string:\n"); gets(a); l = strlen(a); for (p = &a[l-1]; p >= a; p--)原创 2014-07-26 15:51:08 · 630 阅读 · 0 评论 -
Count the digits of any input integers
Given an interger,1) Count its digits2) Output its eve原创 2014-08-08 20:41:40 · 540 阅读 · 0 评论 -
Find all the narcissistic numbers from 100 to 999
In recreational number theory, a narcissistic number (also known as a pluperfect digital invariant (PPDI), an Armstrong number (after Michael F. Armstrong) or a plus perfect number) is a number that is原创 2015-05-24 10:13:02 · 1171 阅读 · 0 评论 -
Find the sum of S = a + aa + aaa + aaaa + aaaaa +......+ aaa...aaa +...
// Find the sum of S = a + aa + aaa + aaaa + aaaaa +......+ aaa...aaa +...#include#includevoid main(){ int a, i, n; long s = 0, sum = 0; printf("Please input the value of a and n :\n"); scanf原创 2013-09-21 21:28:12 · 1337 阅读 · 0 评论 -
Count the number of alphabets, spaces, digits and other characters in one line character
// Count the number of alphabets, spaces, digits and other characters in one line character#includevoid main(){ char c; int i = 0 ,j = 0, m = 0, n = 0; printf("Please input one line characters:原创 2013-09-21 17:05:12 · 1187 阅读 · 0 评论 -
Some Exercises about Pointer (C Programming)
1.#includeint main(){ int i = 3; char c = 4; int *p = &c; printf("*p is %d\n",*p); return 0;}2.#includeint main(){ int a[4] = {1,2,3,4}; int *p = a; int i; printf("Use poi原创 2014-07-15 09:53:42 · 425 阅读 · 0 评论 -
Static Variable, Auto Variable, Global Variable, Local Variable, Register Variable (C)
变量的作用域:(1)局部变量: 即在函数内部定义的变量,形式参数也属于局部变量。局部变量只在定义它的函数内部有效。(2)全局变量: 即所有函数外部定义的变量,其作用范围是从定义变量的位置开始到源程序结束。 变量的存储类型:(1) 自动变量,存储在堆栈中,被关键字auto修饰的局部变量是自动变量,所有的局部变量在默认情况夏都是自动变量。生命周期:在程序执行到声明自动变量的代码块(原创 2014-07-16 10:27:35 · 1111 阅读 · 0 评论 -
Structure (C)
1.#include//Define a structurestruct Student{ int age;};void test(struct Student stu){ printf("The former parameter before revision is: %d\n", stu.age); //Revise the formal paramet原创 2014-07-17 10:59:23 · 626 阅读 · 0 评论 -
Simple Exercises about Marco Definition (C)
1.//宏定义//带参数的宏定义,与函数很像,区别在于//(1)宏定义不涉及存储空间的分配、参数类型匹配、参数传递、返回值问题//(2)函数调用在程序运行时执行,而同替换只在编译预处理阶段进行。所以带参数的宏比函数有更高的执行效率。#include#define D(a) 2*aint main(){ int b = D(3+4); printf("%d\n",b)原创 2014-07-16 10:14:43 · 584 阅读 · 0 评论 -
Header Files Inclusion (C)
文件包含//第一种形式 #include ,直接到C语言库函数头文件所在的目录寻找文件//第二种形式 #include “文件名” 系统现在源程序当前目录下寻找,若找不到,再到操作系统的path路径中查找,最后才到C语言库函数头文件所在目录中查找//#include指令允许嵌套包含,比如a.h包含b.h, b.h包含c.h,但是不允许递归包含,比如a.h 包含b.h, b.h包含a.原创 2014-07-16 11:05:56 · 542 阅读 · 0 评论 -
Enumeration (C)
#includeint main(){ enum season {spring, summer, autumn, winter} s; for(s = spring; s <= winter; s++) { printf("s is %d\n",s); //Enumeration element is regarded as interger constant. }原创 2014-07-17 11:12:54 · 506 阅读 · 0 评论 -
Pointer that points to function (C)
//指向函数的指针//定义的形式:函数的返回值类型(*指针变量名) (形式参数1,形式参数2,...);#includeint sum(int a, int b){ return a + b;}int main(){ //定义一个指针变量p,指向sum函数 int (*p) (int a, int b) = sum; //或者 int (*p)(int,原创 2014-07-15 10:24:21 · 514 阅读 · 0 评论 -
Character String and Character String Array in C Programming
1.#includeint main(){ char b[] = {'R','O','H','E','\0','O','O','\0'}; char a[3] = {'H','E','\0'}; //Remember to add '\0' as the end of a string printf("The string a is %s\n",a); puts(a); /原创 2014-07-15 12:05:53 · 840 阅读 · 0 评论 -
The function that returns the pointer (C Programming)
//返回指针的函数//输入字符串,并将其中的小写字母改为大写字母char *upper(char *str){ char *dest = str; while(*str != '\0') { if(*str >= 'a' && *str <= 'z') { *str -= 'a' - 'A'; } str++; }原创 2014-07-15 10:09:18 · 549 阅读 · 0 评论 -
gcc 编译器对 sqrt 未定义的引用
编译的时候也要在指令后面加 -lm: gcc -o abc abc.c -lm原因:缺少某个库,用 -l 参数将库加入。Linux的库命名是一致的, 一般为 libxxx.so, 或 libxxx.a, libxxx.la, 要链接某个库就用 -lxxx,去掉头 lib 及 "." 后面的 so, la, a 等即可。常见的库链转载 2014-10-03 09:48:22 · 1549 阅读 · 0 评论 -
Calculate the Greatest Commom Divisor (GCD) and Lowest Common Multiple (LCP) of Two Integers
以上方法是用更相减损法求最大公约数,所谓更相减损法,即“以少减多,更相减损,求其等也,以等数约之,等数约之,即除也,其所以相减者皆等数之重叠,故以等数约之”。原创 2014-07-18 14:37:44 · 843 阅读 · 0 评论 -
Two Methods of Finding the sum of 1! + 2! +3! + 4! +...+ 20!
My Method: // Find the sum of 1! + 2! +3! + 4! +...+ 20!int term(int r){ int i; long t = 1; for (i = 1; i <= r; ++i) t = t * i; return t;}#includevoid main(){ int j, n = 20; long原创 2013-09-21 20:34:29 · 728 阅读 · 2 评论 -
Use bubble sort to sort the input intergers
Use bubble sort to sort the input intergers原创 2015-05-27 13:59:09 · 645 阅读 · 0 评论