C和指针习题
文章平均质量分 52
陈思有
I can
展开
-
4.3判断三角形
<br />#include <stdio.h>void main(){ float a,b,c; scanf("%f%f%f",&a,&b,&c); if ( a+b<=c || a+c<=b || b+c<=a ) printf("不是三角形/n"); else { if ( a==b || a==c || b==c ) { if ( b==c && a==c) printf("等边三角形/n");原创 2011-04-17 19:55:00 · 481 阅读 · 0 评论 -
7.4找出最大的数
<br />#include <stdio.h>int max_list( int a[] );void main(){ int a[100],max; int i; for ( i=0; i<100; i++) { scanf("%d",&a[i]); if ( a[i]==-1 ) break; } max = max_list( a ); printf("%d/n",max);}int max_list( i原创 2011-04-19 21:02:00 · 392 阅读 · 0 评论 -
7.1厄密多项式
<br />#include <stdio.h>int hermite( int n, int x );void main(){ int n,x,s; scanf("%d%d",&n,&x); s = hermite( n, x ); printf("%d/n",s);}int hermite( int n, int x ){ if ( n<=0 ) return(1); else if ( n==1 ) return(2*原创 2011-04-19 19:00:00 · 794 阅读 · 0 评论 -
7.3将字符串中的数字字符转换为数字输出
<br />#include <stdio.h>int ascii_to_interger( char *string );void main(){ char str[50]; int n; gets( str ); n = ascii_to_interger( str ); if ( n==-1 ) printf("none/n"); else printf("%d/n",n);}int ascii_to_interger原创 2011-04-19 20:25:00 · 1565 阅读 · 0 评论 -
7.5编输出函数
<br />#include <stdio.h>void print_float( float x ){ printf("%f/n",x);}void print_integer( int x ){ printf("%d/n",x);}void main(){ int a; float b; char c; char d[20]; int i; scanf("%d%f%c%s",&a,&b,&c,d); prin原创 2011-04-19 21:35:00 · 378 阅读 · 0 评论 -
8.2求个人所得税
<br />#include <stdio.h>float single_tax( float income );void main(){ float income,profice; printf("printf insert the income :"); scanf("%f",&income); profice = single_tax( income ); printf("the profice is %.2f/n",profice);}原创 2011-04-20 16:40:00 · 545 阅读 · 0 评论 -
9.11找出the的个数
<br />#include <stdio.h>int num_the( char *str );int main(){ char str[100]; int the; gets(str); the = num_the( str ); printf("the number of the are:%d/n",the);}int num_the( char *str ){ int i,the=0; for ( i=0; *(str+原创 2011-04-22 15:05:00 · 394 阅读 · 0 评论 -
9.10字母回文
<br />#include <stdio.h>#include <string.h>#include <math.h>int palindrome( char *string );void main(){ char str[30]; int n; gets(str); n = palindrome( str ); if ( n==1 ) printf("%s/n",str); else printf("No/n");}原创 2011-04-22 17:45:00 · 912 阅读 · 0 评论 -
9.15将钱的数值用逗号隔开
<br />#include <stdio.h>#include <string.h>void dollars( char *dest, char const *src );void main(){ char str[20],string[25]; gets( str ); dollars( string, str ); printf("%s/n",string);}void dollars( char *dest, char const *s原创 2011-04-23 15:11:00 · 1691 阅读 · 0 评论 -
11.3输入一个字符串,自动分配内存,复制
<br />#include <stdio.h>#include <stdlib.h>#include <string.h>char *str_str( char *str ); int main(){ char str[30],*dst; gets( str ); dst = str_str( str ); printf("%s/n",dst); return EXIT_SUCCESS;}char *str_str( char *st原创 2011-05-04 18:29:00 · 1036 阅读 · 0 评论 -
7.2用递归求两个数的最大公约数
<br />#include <stdio.h>int gcd( int m, int n );void main(){ int m,n,r; scanf("%d%d",&m,&n); r = gcd( m, n); if ( r==0 ) printf("wrong/n"); else printf("%d/n",r);}int gcd( int m, int n ){ int r,temp; if原创 2011-04-19 19:51:00 · 716 阅读 · 0 评论 -
8.3判断单位矩阵
<br />#include <stdio.h>int matrix( int (*a)[] );void main(){ int a[10][10]; int i,j,n; for ( i=0; i<10; i++) for ( j=0; j<10; j++) scanf("%d",&a[i][j]); n = matrix( a ); if ( n==0 ) printf("no/n"); else print原创 2011-04-20 14:24:00 · 1290 阅读 · 0 评论 -
6.3将字符串倒置
<br />#include <stdio.h>void reverse_string( char *string );void main(){ char str[20]; gets(str); printf("%s/n",str); reverse_string( str ); printf("%s/n",str);}void reverse_string( char *string ){ int i,n,m,temp;原创 2011-04-18 16:46:00 · 1871 阅读 · 0 评论 -
2.2大括号
<br />#include <stdio.h>#include <stdlib.h>void main(){ char c; int left=0,right=0; while ( (c=getchar()) != EOF ) { if ( c == '{') left++; else if ( c == '}') { if ( left <= right) printf("extor/n"); else原创 2011-04-17 20:24:00 · 576 阅读 · 0 评论 -
将单词之间多余的空格去掉
<br />#include <stdio.h>#include <string.h>void main(){ void deblank( char string[], int len ); char str[50]; int len; gets(str); len = strlen(str); deblank(str,len); printf("%s/n",str);}void deblank( char string[], i原创 2011-04-15 18:59:00 · 1382 阅读 · 0 评论 -
4.6把一个字符串中某一位数(start)开始,复制len个字符到另一个字符串
<br />#include <stdio.h>#include <string.h>int substr( char dst[], char src[], int start, int len);void main(){ char src[30],dst[30]; int start,len,n,i; gets(src); scanf("%d%d",&start,&len); n = substr(dst,src,start,len); for原创 2011-04-15 20:24:00 · 1644 阅读 · 0 评论 -
当相同的字符串连续出现至少两行时,输出该字符串,只有输出一遍
#include #include void main(){ char a[10][128]; int i,j=0; for (i=0; i原创 2011-04-15 22:13:00 · 702 阅读 · 0 评论 -
4.4将一个字符串中的n个字符复制到另一个字符串中,如果n大于这个字符串的长度,则超出部分以NUL补充
<br />#include <stdio.h>#include <string.h>void copy_n( char dst[], char src[], int n );void main(){ int n,i; char dst[30],src[30]; gets(dst); scanf("%d",&n); copy_n(dst, src, n); for ( i=0; i<n; i++) printf("%c",src[i]); p原创 2011-04-16 00:29:00 · 2394 阅读 · 0 评论 -
4.14和4.15的吃汉堡问题
<br />#include <stdio.h>void eat_hamberger( int x);int hungry( int x);void main(){ int n,j; printf("hungry number:"); scanf("%d",&n); j = hungry(n); if (j==0) { printf("so full/n"); eat_hamberger(j); } else eat_ha原创 2011-04-15 13:24:00 · 423 阅读 · 0 评论 -
6.1找出两个字符串第一个相同的字符
<br />#include <stdio.h>char *find_char( char const *source, char const *chars );void main(){ char source[20],chars[20]; char *p; gets(source); gets(chars); p = find_char(source, chars); if ( p != NULL ) printf("%c/原创 2011-04-18 12:49:00 · 845 阅读 · 0 评论 -
6.2删除一个字符串包含的另一个字符串
<br />#include <stdio.h>int del_substr( char *str, char const *substr );void main(){ char str1[30],str2[20]; int n; gets(str1); gets(str2); n = del_substr( str1, str2 ); if ( n==0 ) { printf("/nno find/n"); printf("%s/n%原创 2011-04-18 18:46:00 · 775 阅读 · 0 评论 -
6.4用筛选法求素数
<br />#include <stdio.h>#include <math.h>#define TRUE 1#define FAULSE 0void main(){ int i,a[1001],j,n; int *p=a; for (i=2; i<1001; i++) /*将数组的各个元素赋值为0*/ *(p+i) = TRUE; for ( i=2; i<1001; i++) { if ( *(p+i)==FAULSE ) cont原创 2011-04-18 21:58:00 · 454 阅读 · 0 评论 -
#ifndef……#define……#endif
//a.h#ifndef _A_H#define _A_Hclass A{pbulic:A(){}~A(){}}#endif// B.h#ifndef _B_H#define _B_H#include "a.h"class B : public A{public:B(){}~B(){}}#endif转载 2011-11-26 15:31:58 · 581 阅读 · 0 评论