常见C语言程序.docx
《常见C语言程序.docx》由会员分享,可在线阅读,更多相关《常见C语言程序.docx(14页珍藏版)》请在冰豆网上搜索。
常见C语言程序
1.输入两个数(iData1,iData2),用指针实现输入的数据从大到小输出,要求从大到小排序在函数中实现,函数形参为指针变量。
#include
voidswap(int*a,int*b);
voidmain()
{
intiData1,iData2;
int*p1,*p2;
printf("请输入两个整数(用逗号隔开):
\n");
scanf("%d,%d",&iData1,&iData2);
p1=&iData1;
p2=&iData2;
if(iData1{printf("交换前:%d,%d\n",*p1,*p2);swap(&iData1,&iData2);printf("swap中:%d,%d\n",*p1,*p2);printf("交换后:%d,%d\n",*p1,*p2);}else{printf("交换前:%d,%d\n",*p1,*p2);printf("swap中:%d,%d\n",*p1,*p2);printf("交换后:%d,%d\n",*p1,*p2);}}voidswap(int*a,int*b){intc;c=*a;*a=*b;*b=c;}2.将一个数插入到按升序排序的数列中,新数列仍然有序,用指针实现。#include#include#defineN10voidmain(){inta[N],i,k,t;int*p=&a[8];printf("请输入9个数:");for(i=0;i{scanf("%d",a+i);}printf("请输入1个数:");scanf("%d",&a[9]);for(i=9;i>=1;i--){if(*p>a[i]){t=*p;*p=a[i];a[i]=t;}p--;}for(i=0;i{printf("%d",a[i]);}}3.编写一段程序,输入一个3×4的整型矩阵,输出矩阵中的最大值及其下标。4.随机存入n个数据存入数组,通过指针参数传递将数组中的最大元素与第一个元素交换,最小元素与最后一个元素交换。#include#defineN100voidswap(int*a,int*b){intc;c=*a;*a=*b;*b=c;}voidmain(){inti,n;inta[N],*p,*pmax,*pmin,*first,*last;printf("共有几个数(1~100)?");scanf("%d",&n);printf("它们是:");for(p=a;p{scanf("%d",p);}pmax=a;for(p=a;p{if(*p>*pmax){pmax=p;}}pmin=a;for(p=a;p{if(*p<*pmin){pmin=p;}}printf("数组为:");for(i=0;i{printf("%d",a[i]);}printf("\n");printf("最大数是%d\n",*pmax);printf("最小数是%d\n",*pmin);first=a;last=a+n-1;swap(first,pmax);swap(last,pmin);printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:\n");for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
printf("交换前:
%d,%d\n",*p1,*p2);
swap(&iData1,&iData2);
printf("swap中:
printf("交换后:
}
else
voidswap(int*a,int*b)
intc;
c=*a;
*a=*b;
*b=c;
2.将一个数插入到按升序排序的数列中,新数列仍然有序,用指针实现。
#defineN10
inta[N],i,k,t;
int*p=&a[8];
printf("请输入9个数:
");
for(i=0;i{scanf("%d",a+i);}printf("请输入1个数:");scanf("%d",&a[9]);for(i=9;i>=1;i--){if(*p>a[i]){t=*p;*p=a[i];a[i]=t;}p--;}for(i=0;i{printf("%d",a[i]);}}3.编写一段程序,输入一个3×4的整型矩阵,输出矩阵中的最大值及其下标。4.随机存入n个数据存入数组,通过指针参数传递将数组中的最大元素与第一个元素交换,最小元素与最后一个元素交换。#include#defineN100voidswap(int*a,int*b){intc;c=*a;*a=*b;*b=c;}voidmain(){inti,n;inta[N],*p,*pmax,*pmin,*first,*last;printf("共有几个数(1~100)?");scanf("%d",&n);printf("它们是:");for(p=a;p{scanf("%d",p);}pmax=a;for(p=a;p{if(*p>*pmax){pmax=p;}}pmin=a;for(p=a;p{if(*p<*pmin){pmin=p;}}printf("数组为:");for(i=0;i{printf("%d",a[i]);}printf("\n");printf("最大数是%d\n",*pmax);printf("最小数是%d\n",*pmin);first=a;last=a+n-1;swap(first,pmax);swap(last,pmin);printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:\n");for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
scanf("%d",a+i);
printf("请输入1个数:
scanf("%d",&a[9]);
for(i=9;i>=1;i--)
if(*p>a[i])
t=*p;
*p=a[i];
a[i]=t;
p--;
for(i=0;i{printf("%d",a[i]);}}3.编写一段程序,输入一个3×4的整型矩阵,输出矩阵中的最大值及其下标。4.随机存入n个数据存入数组,通过指针参数传递将数组中的最大元素与第一个元素交换,最小元素与最后一个元素交换。#include#defineN100voidswap(int*a,int*b){intc;c=*a;*a=*b;*b=c;}voidmain(){inti,n;inta[N],*p,*pmax,*pmin,*first,*last;printf("共有几个数(1~100)?");scanf("%d",&n);printf("它们是:");for(p=a;p{scanf("%d",p);}pmax=a;for(p=a;p{if(*p>*pmax){pmax=p;}}pmin=a;for(p=a;p{if(*p<*pmin){pmin=p;}}printf("数组为:");for(i=0;i{printf("%d",a[i]);}printf("\n");printf("最大数是%d\n",*pmax);printf("最小数是%d\n",*pmin);first=a;last=a+n-1;swap(first,pmax);swap(last,pmin);printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:\n");for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
printf("%d",a[i]);
3.编写一段程序,输入一个3×4的整型矩阵,输出矩阵中的最大值及其下标。
4.随机存入n个数据存入数组,通过指针参数传递将数组中的最大元素与第一个元素交换,最小元素与最后一个元素交换。
#defineN100
inti,n;
inta[N],*p,*pmax,*pmin,*first,*last;
printf("共有几个数(1~100)?
scanf("%d",&n);
printf("它们是:
for(p=a;p{scanf("%d",p);}pmax=a;for(p=a;p{if(*p>*pmax){pmax=p;}}pmin=a;for(p=a;p{if(*p<*pmin){pmin=p;}}printf("数组为:");for(i=0;i{printf("%d",a[i]);}printf("\n");printf("最大数是%d\n",*pmax);printf("最小数是%d\n",*pmin);first=a;last=a+n-1;swap(first,pmax);swap(last,pmin);printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:\n");for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
scanf("%d",p);
pmax=a;
for(p=a;p{if(*p>*pmax){pmax=p;}}pmin=a;for(p=a;p{if(*p<*pmin){pmin=p;}}printf("数组为:");for(i=0;i{printf("%d",a[i]);}printf("\n");printf("最大数是%d\n",*pmax);printf("最小数是%d\n",*pmin);first=a;last=a+n-1;swap(first,pmax);swap(last,pmin);printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:\n");for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
if(*p>*pmax)
pmax=p;
pmin=a;
for(p=a;p{if(*p<*pmin){pmin=p;}}printf("数组为:");for(i=0;i{printf("%d",a[i]);}printf("\n");printf("最大数是%d\n",*pmax);printf("最小数是%d\n",*pmin);first=a;last=a+n-1;swap(first,pmax);swap(last,pmin);printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:\n");for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
if(*p<*pmin)
pmin=p;
printf("数组为:
for(i=0;i{printf("%d",a[i]);}printf("\n");printf("最大数是%d\n",*pmax);printf("最小数是%d\n",*pmin);first=a;last=a+n-1;swap(first,pmax);swap(last,pmin);printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:\n");for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
printf("\n");
printf("最大数是%d\n",*pmax);
printf("最小数是%d\n",*pmin);
first=a;
last=a+n-1;
swap(first,pmax);
swap(last,pmin);
printf("最大元素与第一个元素交换,最小元素与最后一个元素交换为:
for(i=0;iprintf("%d",a[i]);}5.通过指针参数传递,计算自然数n的阶乘。6.以下程序将数组a中的数据按逆序存放#include#defineM8voidmain(){inta[M],i,j,t;for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
5.通过指针参数传递,计算自然数n的阶乘。
6.以下程序将数组a中的数据按逆序存放
#defineM8
inta[M],i,j,t;
for(i=0;iscanf("%d",a+i);i=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
i=0;
j=M-1;
while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
t=*(a+i);
*(a+i)=*(a+j);
*(a+j)=t;
i++;
j--;
for(i=0;iprintf("%3d",*(a+i));}7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差#include#includefloatfindmax(float*x,intm,intn){inti,j;floatmax=*x;for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
printf("%3d",*(a+i));
7.以下程序的功能是求二维数组a中的最大值与二维数组b中的最大值之差
floatfindmax(float*x,intm,intn)
inti,j;
floatmax=*x;
for(i=0;ifor(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
for(j=0;jif(*(x+i*m+j)>max){max=*(x+i*m+j);}returnmax;}voidmain(){floata[3][3],b[3][2];inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%f",&a[i][j]);}for(i=0;i<2;i++)for(j=0;j<3;j++){scanf("%f",&b[i][j]);}printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));}8.99乘法表#includevoidmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%1dx%1d=%-4d",j,i,j*i);}printf("\n");}}9.计算n的阶乘#includevoidmain(){inti;floatf=1;for(i=1;i<=10;i++){f=f*i;printf("%2d!=%.0f\n",i,f);}}10.开发“家乐福收银系统”#includevoidmain(){intnum,count;charname,c,q;floatip,op,cut;printf("*****************⊙*****************\n");printf("**\n");printf("**\n");printf("*◎录入商品信息*\n");printf("**\n");printf("**\n");printf("*****************⊙*****************\n");do{printf("请输入商品编号:");scanf("%d",&num);printf("请输入商品名称:");scanf("%s",&name);printf("请输入商品进价:");scanf("%f",&ip);printf("请输入商品售价:");scanf("%f",&op);printf("请输入商品折扣:");scanf("%f",&cut);printf("请输入商品数量:");scanf("%d",&count);printf("您刚录入的信息如下:\n");printf("编号名称进价售价折扣数量\n");printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);printf("本次输入完毕,按q键退出,其它键继续输入\n");fflush(stdin);c=getchar();}while(c!='q');}11.已知五个字符串"China","American","Japan","France","Australia",编程将它们按从小到大的顺序排列起来。#include#includevoidmain(){intj,k;chart[81],b[5][81]={"China","American","Japan","France","Australia"};for(j=0;j<4;j++)for(k=j+1;k<5;k++)if(strcmp(b[j],b[k])>0){strcpy(t,b[j]);strcpy(b[j],b[k]);strcpy(b[k],t);}for(j=0;j<5;j++)printf("%s\n",b[j]);}12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。#include#defineN100voidmain(){charstr[N];inti,z=0,k=0,s=0,q=0;puts("输入任意一行字符:");gets(str);for(i=0;str[i]!=0;i++){if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z')){z++;}elseif(str[i]='\0'){k++;}elseif(('0'<=str[i]&&str[i]<='9')){s++;}else{q++;}}printf("您输入的字母的个数为%d\n",z);printf("您输入的空格的个数为%d\n",k);printf("您输入的数字的个数为%d\n",s);printf("其它字符的的个数为%d\n",q);}13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。#include#defineN100voidmain(){charcData1[N],cData2[N];char*p1
if(*(x+i*m+j)>max)
max=*(x+i*m+j);
returnmax;
floata[3][3],b[3][2];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%f",&a[i][j]);
for(i=0;i<2;i++)
scanf("%f",&b[i][j]);
printf("%f\n",findmax(a[0],3,3)-findmax(b[0],2,3));
8.99乘法表
for(i=1;i<=9;i++)
for(j=1;j<=i;j++)
printf("%1dx%1d=%-4d",j,i,j*i);
9.计算n的阶乘
inti;
floatf=1;
for(i=1;i<=10;i++)
f=f*i;
printf("%2d!
=%.0f\n",i,f);
10.开发“家乐福收银系统”
intnum,count;
charname,c,q;
floatip,op,cut;
printf("*****************⊙*****************\n");
printf("**\n");
printf("*◎录入商品信息*\n");
do
printf("请输入商品编号:
scanf("%d",&num);
printf("请输入商品名称:
scanf("%s",&name);
printf("请输入商品进价:
scanf("%f",&ip);
printf("请输入商品售价:
scanf("%f",&op);
printf("请输入商品折扣:
scanf("%f",&cut);
printf("请输入商品数量:
scanf("%d",&count);
printf("您刚录入的信息如下:
printf("编号名称进价售价折扣数量\n");
printf("%-4d%-4c%-6.2f%-4.2f%-6.2f%-4d\n",num,name,ip,op,cut,count);
printf("本次输入完毕,按q键退出,其它键继续输入\n");
fflush(stdin);
c=getchar();
while(c!
='q');
11.已知五个字符串"China","American","Japan","France","Australia",
编程将它们按从小到大的顺序排列起来。
intj,k;
chart[81],b[5][81]={"China","American","Japan","France","Australia"};
for(j=0;j<4;j++)
for(k=j+1;k<5;k++)
if(strcmp(b[j],b[k])>0)
strcpy(t,b[j]);
strcpy(b[j],b[k]);
strcpy(b[k],t);
for(j=0;j<5;j++)
printf("%s\n",b[j]);
12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
本题要求输入一行字符,应使用gets()函数,不能使用scanf()函数输入。
charstr[N];
inti,z=0,k=0,s=0,q=0;
puts("输入任意一行字符:
gets(str);
for(i=0;str[i]!
=0;i++)
if(('A'<=str[i]&&str[i]<='Z')||('a'<=str[i]&&str[i]<='z'))
z++;
elseif(str[i]='\0')
k++;
elseif(('0'<=str[i]&&str[i]<='9'))
s++;
q++;
printf("您输入的字母的个数为%d\n",z);
printf("您输入的空格的个数为%d\n",k);
printf("您输入的数字的个数为%d\n",s);
printf("其它字符的的个数为%d\n",q);
13.编一程序,用字符指针将两个字符串连接起来,连接功能用函数实现,要求不使用strcat函数。
charcData1[N],cData2[N];
char*p1
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1