随笔分类 - c语言
摘要:/* 程序的功能为:判断从键盘上输入的一个字符,并按下列要求输出。 若该字符是数字 输出字符串"0-9" 若该字符是大写字母 输出字符串"A-Z" 若该字符是小写字母 输出字符串"a-z" 若该字符是其他字符 输出字符串"!,@,…" */ #include <stdio.h> void main(
阅读全文
摘要:#include <stdio.h> //程序功能:输入一个6*6矩阵,将其主对角线上的元素置1,次对角线置-1,其余元素为0 main() { int 【1】; int i,j; for(i=0;【2】;i++) { 【3】=1; 【4】=-1; } for(i=0;i<=5;i++) { for
阅读全文
摘要:#include <stdio.h> //程序功能:输入一行字符,分别统计其中英文字母、数字和其他字符的个数 main() { char c; int i=0,j=0,k=0; while(【1】) { if(c>='0' && c<='9') 【2】; else if(【3】) j++; else
阅读全文
摘要:#include <stdio.h> //程序功能:求s=1+2+3+4+5+....+100 //【】位置需要填写相应内容,保证程序能正常运行,无警告提示。 main() { 【1】; for(a=1;a<=【2】;a++) s=【3】; printf("s=%d\n",【4】); getchar
阅读全文
摘要://交换任意两个整型变量的值 //【】位置需要填写相应内容,保证程序能正常运行,无警告提示。 【1】 main() { int a=1,b=2; printf("a=%d,b=%d\n",a,b); a=【2】; b=【3】; a=【4】; printf("a=%d,b=%d\n",a,b); ge
阅读全文
摘要:#include <stdio.h> //任意整型数组,由连续几个数组成,少其中一个数,利用程序求出少得数 main() { int a[5]={0,2,4,1},x=0,i; for(i=0;i<4;i++) x^=a[i]; for(i=0;i<=4;i++) x^=i; printf("%d"
阅读全文
摘要:#include <stdio.h> //⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽ //交换两个整型变量的值 main() { int a,b; scanf("%d%d",&a,&b); printf("a=%d,b=%d\n"); a=⑴; b=⑵; a=⑶; printf("a=%d,b=%d\n"); getch
阅读全文
摘要:#include <stdio.h> #include <string.h> int fh(char ab[]) { int len=strlen(ab),a=0; for(a=0;a<=len;a++) if(ab[a]!=ab[len-a-1]) return 0; return 1; } ma
阅读全文
摘要:#include <stdio.h> #include <string.h> main() { char zf[7],zfa[7]; int a=0,b=0,c=0,len1,len2; gets(zf); gets(zfa); len1=strlen(zf),len2=strlen(zfa); w
阅读全文
摘要:#include <stdio.h> #include <string.h> main() { char ch[100]; int i=0,n=0; gets(ch); while(ch[i]!='\0') { if(i==0) { if(ch[i]>='a'&& ch[i]<='z') ch[i]
阅读全文
摘要:#include<stdio.h> #include<string.h> #include <stdlib.h> //利用<string.h>中的strtok函数,缺点就是异常复杂,但是优点就是可以用各种字符来分割输入的字符串 int main(){ char num[100000];//定义字符串
阅读全文
摘要:#include <stdio.h> main() { struct sk{ int a;float b; }data,*p; p=&data; data.a=10; printf("%d\n",(*p).a); printf("%d\n",p->a); getchar(); } #include
阅读全文
摘要:#include <stdio.h> main() { char a[3][10]={"beijing","shanghai","tianjin"},*pa=a[0]; printf("%s\n",*(a+1)); printf("%s\n",a+1); printf("%s\n",*a+1); p
阅读全文
摘要:#include <stdio.h> int sx(int n) { int a; for(a=2;a<n;a++) if(n%a==0) return 0; return 1; } void sxa(int b) { int c=1,a=b; while(c<=5) { a=a+1; if(sx(
阅读全文
摘要:#include <stdio.h> main() { int n,a[10]={0}; scanf("%d",&n); while(n>0&&n<=99) { if(n>0 && n<=10) a[(n-1)/10]++; else a[n/10]++; scanf("%d",&n); } for
阅读全文
摘要:#include <stdio.h> main() { int i,n,s; s=0; scanf("%d",&n); for(i=1;i<n;i++) if(n%i==0) s=s+i; if(s==n) printf("%d是完数",n); else printf("%d不是完数",n); ge
阅读全文
摘要:#include <stdio.h> int zs(int n) { int a; for(a=2;a<n;a++) if(n%a==0) return 0; return 1; } main() { int a,b,c=0; scanf("%d",&a); for(b=a-1;b>=2;b--)
阅读全文
摘要:#include <stdio.h> #include <string.h> main() { char zf[100],ch; int a,b=0,c; gets(zf); c=strlen(zf); if(c!=11 || zf[0]!='1') b=1; for(a=0;a<11;a++) {
阅读全文
摘要:#include <stdio.h> float fh(int n) { if(n==1) return 1; else return 1/(n-1+1/fh(n-1)); } main() { float aa=0; int a,b; for(a=1;fh(a)>=0.001;a++) //pri
阅读全文
摘要:#include <stdio.h> //假设商品销售额为16800(不开票),客户需要开发票,税(0.12)需要开在发票中 //编程计算最后的开票金额 main() { float a=16800,b=0.12,c,d=16800; c=a*b; while(c>=1) { d=d+c; c=c*
阅读全文