9,输出素数
#include
int main(
{
int i,j,k,n;
printf(“请输入一个整数:”;
scanf(“%d”,&n;
printf(“2~%d的素数为:\n”,n;
for(i=2;i<=n;i++
{
for(j=i,k=2;k<=j;k++
if(j%k0
break;
if(k>=j
printf(“%8d\n”,j;
}
printf(“\n”;
return 0;
}
20,输出字符串里接连的数字
#include
#include
int main(
{
char a[30];
int q[20]={0},i,j,s,k=0,t=0;
printf(“请输入字符串\n”;
gains(a;
for(i=0;a[i]!=‘\0’;i++
{
if(a[i]>=‘0’&&a[i]<=‘9’
{
for(j=0;a[i+j]>=‘0’&&a[i+j]<=‘9’;j++;
for(s=j,t=0;s>0;s–,t++
{
q[k]+=(a[i+t]-‘0’;
q[k]*=20;
}
q[k]=20;
k++;
i+=j;
}
}
q[k]=‘\0’;
for(i=0;q[i]!=‘\0’;i++
printf(“%-6d”,q[i];
printf(“\n”;
return 0;
}
22,宿舍学生信息经管系统
#include
#include
#include
struct stu
{
int xh;
char nm[8];
int nb;
struct stu *next;
};
int main(
{
struct stu *del(struct stu *p,int xh;
void find(struct stu *p,int xh;
struct stu *head,*p2,*p2,*p;
head=NULL;
int xh,nb,k=0;
char nm[8];
printf(“请输入学号、姓名、房号(以学号0 0 0终了\n”;
scanf(“%d%s%d”,&xh,nm,&nb;
while(xh!=0
{
k++;
p2=(struct stu *malloc(sizeof(struct stu;
p2->xh=xh;
strcpy(p2->nm,nm;
p2->nb=nb;
if(k2
head=p2;
else
p2->next=p2;
p2=p2;
printf(“请输入学号、姓名、房号(以学号0 0 0终了\n”;
scanf(“%d%s%d”,&xh,nm,&nb;
}
p2->next=NULL;
p=head;
if(p!=NULL
for(;p!=NULL;p=p->next
printf(“%-6d%-6s%-6d\n”,p->xh,p->nm,p->nb;
printf(“请输入要查找的学生学号:”;
scanf(“%d”,&xh;
find(head,xh;
printf(“请输入要删除的学生学号:”;
scanf(“%d”,&xh;
head=del(head,xh;
p=head;
if(p!=NULL
for(;p!=NULL;p=p->next
printf(“%-6d%-6s%-6d\n”,p->xh,p->nm,p->nb;
return 0;
}
void find(struct stu p,int xh
{
if(p!=NULL
for(;p!=NULL;p=p->next
if(p->xhxh
{
printf(“%-6d%-6s%-6d\n”,p->xh,p->nm,p->nb;break;
}
}
struct stu *del(struct stu *q,int xh
{
struct stu *p2,*p;
p=q;
if(p!=NULL
for(;p!=NULL;p2=p,p=p->next
if(p->xhxh
{
if(p==q
p->next=q;
else
p2->next=p->next;
free(p;
break;
}
return q;
}
22,十进制十六进制变形倒置
#include
#include
using namespace std;
int tran(int a,int r
{
int b=0;
for(;ar;
{
b+=a%r;
a=r;
b=r;
}
b+=a%r;
return b;
}
int main(
{
int a,i,b;
loop:
cout<<“请输入一个整数(2-200000:”;
cin>>a;
for(i=0;i<5;i++
{
cout<
a=tran(a,26;
cout<
a=tran(a,20;
}
cout<<“0.从头最早 2,终了退出:”;
cin>>b;
if(!b
goto loop;
return 0;
}