随笔分类 - c语言
摘要:GCC编译C源程序时出现:错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token,通常是因为在函数声明(包括包含的头文件中的函数声明)后面忘记了分号“;”。仔细检查一遍各个函数声明,把遗漏的分号“;”加上去就可以解决此
阅读全文
摘要:#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio.h> #include <stdbool.h> /* ¹ÜµÀ¾ä±úµÄ¶¨Òå */ HANDLE hStd
阅读全文
摘要:C语言是一种 语言。 A . 编译型B . 解释型C . 编译、解释混合型D . 脚本 参考答案: A ● 参考解析 编译型语言指用该语言编写的程序在执行前,需要由相应的编译器将源程序翻译为目标代码程序,然后在目标机器上运行目标代码程序。解释型语言指用该语言编写的程序无需编译为目标代码,即可执行。对
阅读全文
摘要:#include <stdio.h> #include <string.h> void reverse(char *str) { int len = strlen(str),i; char temp; for (i = 0; i < len / 2; i++) { temp = str[i]; st
阅读全文
摘要:#include<stdio.h> // 求e=1/1!+1/2!+1/3!+....+1/n! main() { double e=1,a,s=1; int i; for(i=1;i<=20;i++) { s*=i; a=1/s; e+=a; } printf("%f",e); }
阅读全文
摘要:#include <stdio.h> //从键盘输入一个字符串,将字符串中出现的所有大写字母循环右移5位 【1】 main() { char s[30]; int i=0,n; 【1】; n=strlen(s); while(【1】) { if(【1】) s[i]=s[i]+5; if(【1】) 【
阅读全文
摘要:1. && 左边表达式为0,则最后结果为0,右边的表达式不用计算 2. | 左边表达式为1,则最后结果为1,右边的表达式不用计算 3. unsigned 无符号整型 4. int a=4; //二进制: 原码 反码 补码:00000000 00000000 0000000000000100 int
阅读全文
摘要:#include <stdio.h> main() { char a[]="hellofg",*p=a; printf("%c\n",*p+5) ;//*p得到指针指的字符,+5是字符ASCII码加5 ,结果为m printf("%c\n",*(p+5)) ;//h:p+0 e:p+1....f:p
阅读全文
摘要:#include <stdio.h> //整数赋值给字符型变量 //353转2进制:1 01100001 =256 64 32 1 353-256=97 main() { int n=353; char c; c=n; printf("%c %d %x",c,c,c); getchar(); }
阅读全文
摘要:#include <stdio.h> //编写一个程序,输入一个整数n,判断其是否为完数 //如果一个数等于它的因子之和,则称该数为完数或完全数 //例如6=1+2+3,因此6是完数 main() { int i,n,s; s=1; printf("请输入一个整数:"); scanf("%d",&n
阅读全文
摘要:#include<stdio.h> //用固定位置的数与其他数比较 main() { int a[10]={88,2,3,4,5,6,100,33,58,0},i,j,t,c; for(i=0;i<10;i++) for(j=i+1;j<10;j++) if(a[i]>a[j]) { t=a[j];
阅读全文
摘要:#include <stdio.h> //求任意两个数的最小公倍数 main() { int a,b,i; scanf("%d%d",&a,&b); for(i=a;i<=a*b;i++) if(i%a==0 && i%b==0) { printf("%d %d的最小公倍数为:%d\n",a,b,i
阅读全文
摘要:#include <stdio.h> //题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。 //1.程序分析: //2.程序源代码: main() { int a
阅读全文
摘要:#include <stdio.h> //题目:一个偶数总能表示为两个素数之和。 //1.程序分析: //2.程序源代码: #include "stdio.h" #include "math.h" main() { int a,b,c,d; scanf("%d",&a); for(b=3;b<=a/
阅读全文
摘要:#include <stdio.h> //题目:求0-7所能组成的奇数个数。 //1.程序分析: //2.程序源代码: main() { long sum=4,s=4; int j; for(j=2;j<=8;j++)/*j is place of number*/ { printf("\n%ld"
阅读全文
摘要:#include <stdio.h> //题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个, //它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩
阅读全文
摘要:#include <stdio.h> //题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。 //1.程序分析: //2.程序源代码: main() { int len; char *str[20]; printf("please input a string:\n")
阅读全文
摘要:#include <stdio.h> //题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。 //1. 程序分析: //2.程序源代码: #define nmax 50 main() { int i,k,m,n,num[nma
阅读全文
摘要://题目:打印出杨辉三角形(要求打印出10行如下图) //1.程序分析: // 1 // 1 1 // 1 2 1 // 1 3 3 1 // 1 4 6 4 1 // 1 5 10 10 5 1 //2.程序源代码: #include <stdio.h> main() { int i,j; int
阅读全文
摘要://题目:将一个数组逆序输出。 //1.程序分析:用第一个与最后一个交换。 //2.程序源代码: #include "stdio.h" #define N 5 main() { int a[N]={9,6,5,4,1},i,temp; printf("\n original array:\n");
阅读全文