主题:经典c程序100例==81--90
lmh16659
[专家分:150] 发布于 2004-05-23 23:18:00
经典c程序100例==81--90
【程序81】
题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。
1.程序分析:
2.程序源代码:
output(long b,long i)
{ printf("\n%ld/%ld=809*%ld+%ld",b,i,i,b%i);
}
main()
{long int a,b,i;
a=809;
for(i=10;i<100;i++)
{b=i*a+1;
if(b>=1000&&b<=10000&&8*i<100&&9*i>=100)
output(b,i); }
}
==============================================================
【程序82】
题目:八进制转换为十进制
1.程序分析:
2.程序源代码:
main()
{ char *p,s[6];int n;
p=s;
gets(p);
n=0;
while(*(p)!='\0')
{n=n*8+*p-'0';
p++;}
printf("%d",n);
}
==============================================================
【程序83】
题目:求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",sum);
if(j<=2)
s*=7;
else
s*=8;
sum+=s;}
printf("\nsum=%ld",sum);
}
==============================================================
【程序84】
题目:一个偶数总能表示为两个素数之和。
1.程序分析:
2.程序源代码:
#include "stdio.h"
#include "math.h"
main()
{ int a,b,c,d;
scanf("%d",&a);
for(b=3;b<=a/2;b+=2)
{ for(c=2;c<=sqrt(b);c++)
if(b%c==0) break;
if(c>sqrt(b))
d=a-b;
else
break;
for(c=2;c<=sqrt(d);c++)
if(d%c==0) break;
if(c>sqrt(d))
printf("%d=%d+%d\n",a,b,d);
}
}
==============================================================
【程序85】
题目:判断一个素数能被几个9整除
1.程序分析:
2.程序源代码:
main()
{ long int m9=9,sum=9;
int zi,n1=1,c9=1;
scanf("%d",&zi);
while(n1!=0)
{ if(!(sum%zi))
n1=0;
else
{m9=m9*10;
sum=sum+m9;
c9++;
}
}
printf("%ld,can be divided by %d \"9\"",sum,c9);
}
==============================================================
【程序86】
题目:两个字符串连接程序
1.程序分析:
2.程序源代码:
#include "stdio.h"
main()
{char a[]="acegikm";
char b[]="bdfhjlnpq";
char c[80],*p;
int i=0,j=0,k=0;
while(a[i]!='\0'&&b[j]!='\0')
{if (a[i] { c[k]=a[i];i++;}
else
c[k]=b[j++];
k++;
}
c[k]='\0';
if(a[i]=='\0')
p=b+j;
else
p=a+i;
strcat(c,p);
puts(c);
}
==============================================================
【程序87】
题目:回答结果(结构体变量传递)
1.程序分析:
2.程序源代码:
#include "stdio.h"
struct student
{ int x;
char c;
} a;
main()
{a.x=3;
a.c='a';
f(a);
printf("%d,%c",a.x,a.c);
}
f(struct student b)
{
b.x=20;
b.c='y';
}
==============================================================
【程序88】
题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。
1.程序分析:
2.程序源代码:
main()
{int i,a,n=1;
while(n<=7)
{ do {
scanf("%d",&a);
}while(a<1||a>50);
for(i=1;i<=a;i++)
printf("*");
printf("\n");
n++;}
getch();
}
==============================================================
【程序89】
题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:
每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。
1.程序分析:
2.程序源代码:
main()
{int a,i,aa[4],t;
scanf("%d",&a);
aa[0]=a%10;
aa[1]=a%100/10;
aa[2]=a%1000/100;
aa[3]=a/1000;
for(i=0;i<=3;i++)
{aa[i]+=5;
aa[i]%=10;
}
for(i=0;i<=3/2;i++)
{t=aa[i];
aa[i]=aa[3-i];
aa[3-i]=t;
}
for(i=3;i>=0;i--)
printf("%d",aa[i]);
}
==============================================================
【程序90】
题目:专升本一题,读结果。
1.程序分析:
2.程序源代码:
#include "stdio.h"
#define M 5
main()
{int a[M]={1,2,3,4,5};
int i,j,t;
i=0;j=M-1;
while(i {t=*(a+i);
*(a+i)=*(a+j);
*(a+j)=t;
i++;j--;
}
for(i=0;i printf("%d",*(a+i));
}
3 楼
51last [专家分:0] 发布于 2004-06-23 20:10:00
#include <stdio.h>
typedef struct node
{
int num;
char name[20];
char sex[10];
int age;
int english;
int math;
int computer;
int zfen;
struct node *next;
} Student;
Student* Initiate_Student();
Student* Create_Student(Student *head);
Student* Find_Student(Student *head, int num);
Student* Insert_Student(Student *head);
Student* Delete_Student(Student *head);
int ge=0;
float zhonfen[100];
float pinjunf[100];
int main (void)
{
Student *head, *p;
int choose, num;
head = Initiate_Student();
printf("%s\n%s\n",
"#####################Student#######################",
"__________________________________________________");
head = Create_Student(head);
while (1)
{
printf("%s\n%s\n%s\n%s\n%s\n%s\n%s",
"1:see student 2:zhao xue sheng xu lie hao 3:xing ming zhao",
"4:xue hao zhao 5:chai ru xue sheng xingxi 6:san chu xue sheng xingxi",
"7:zhong feng yu ping jun feng 8:mei ge xue sheng feng shu",
"9:zhong feng zui gao xue sheng xingxi 10:zhong feng zui di xue sheng xingxi",
"11:ge feng su duan ren su",
"0:exit",
"please:");
scanf("%d", &choose);
switch (choose)
{
case 1:
Print_Student(head);
break;
case 2:
printf("input xu lie hao:");
scanf("%d", &num);
p = Find_Student(head, num);
printf("gai xue sheng xingxi:\n");
printf("number\tnum\tname\tsex\tenglish-math-computer\tage\n");
printf("(%d)\t%4d\t%s\t%s\t%d-%d-%d\t%2d\n\n", num, p -> num,
p -> name, p -> sex,p -> english, p -> math,
p -> computer, p -> age);
break;
case 3:
LocateName_Student(head);
break;
case 4:
printf("input xu lie hao:");
scanf("%d", &num);
LocateNum_Student(head, num);
break;
case 5:
head = Insert_Student(head);
break;
case 6:
head = Delete_Student(head);
break;
case 7:
chengji(head);
break;
case 8:
zhongfen(head);
break;
case 9:
/*findmax(head);*/
break;
case 10:
/*findmin(head);*/
break;
case 11:
suxue(head);
break;
case 0:
exit(0);
default:
printf("\nSorry!\n");
}
}
}
Student* Initiate_Student ()
{
Student *head;
head = (Student *) malloc (sizeof(Student));
head -> next = NULL;
return (head);
}
Student* Create_Student (Student *head)
{
Student *new, *end;
int age, num;
int i,j=0;
int english,math,computer;
char input;
int count;
int choose, next = 1;
end = head;
while (next)
{
count = 0;
new = (Student *) malloc (sizeof(Student));
printf("input num:");
scanf("%d", &num);
getchar();
printf("input name:");
while ((input = getchar()) != '\n')
{
new -> name[count] = input;
count++;
}
new -> name[count] = '\0';
for(i=1;;i++)
{printf("qing xuan ze(1:M 2:F):");
scanf("%d", &choose);
switch (choose)
{
case 1:
strcpy (new -> sex, "M");
j=0;
break;
case 2:
strcpy (new -> sex, "F");
j=0;
break;
default:
printf("\nSorry please input!\n");
j=1;
}
if(j==0) break;
}
printf("input age:");
scanf("%d", &age);
printf("input english:");
scanf("%d", &english);
printf("input math:");
scanf("%d", &math);
printf("input computer:");
scanf("%d", &computer);
ge=ge+1;
zhonfen[ge]=english+math+computer;
pinjunf[ge]=zhonfen[ge]/3;
new -> num = num;
new -> age = age;
new -> english =english;
new -> math = math;
new -> computer = computer;
new -> zfen = zhonfen[ge];
end -> next = new;
end = new;
getchar();
printf("ji xu input(Y/N)?");
scanf("%c", &input);
if (input == 'Y' || input == 'y')
next = 1;
else
next = 0;
}
return (head);
}
int Print_Student (Student *head)
{
Student *p;
int j = 1;
p = head;
printf("xue sheng xing xi:\n\n");
printf("number\tnum\tname\tsex\tenglish-math-computer\tage\n");
printf("-----------------------------------------------------\n");
if (head != NULL)
{
p = p -> next;
while (p != NULL)
{
printf("(%d)", j);
j++;
printf("\t%4d\t%s\t%s\t%d-%d-%d\t%2d\n", p -> num, p -> name,
p -> sex,p -> english, p -> math,
p -> computer, p -> age);
p = p -> next;
if(j>ge) break;
}
}
printf("-----------------------------------------------------\n");
printf("have %d ge xue sheng.\n\n", j - 1);
return;
}
Student* Find_Student (Student *head, int i)
{
Student *p;
int j = 0;
p = head;
while ((p -> next != NULL) && (j < i))
{
p = p -> next;
j++;
}
if (i == j)
return (p);
else
{
printf("Sorry gai wei zi bu cheng zai!\n");
return 0;
}
}
Student* Insert_Student (Student *head)
{
Student *p, *s;
int i,j=0;
int age, num;
int english,math,computer;
char input;
int count;
int choose, insertLocation;
printf("input num:");
scanf("%d", &insertLocation);
p = Find_Student(head, insertLocation - 1);
if (p == NULL)
{
printf("bu cheng zai %d ge wei zi!\n", insertLocation);
return 0;
}
else
{
count = 0;
s = (Student *) malloc (sizeof(Student));
printf("input num:");
scanf("%d", &num);
getchar();
printf("input name:");
while ((input = getchar()) != '\n')
{
s -> name[count] = input;
count++;
}
s -> name[count] = '\0';
for(i=1;;i++)
{printf("qing xuan ze(1:M 2:F):");
scanf("%d", &choose);
switch (choose)
{
case 1:
strcpy (s -> sex, "M");
j=0;
break;
case 2:
strcpy (s -> sex, "F");
j=0;
break;
default:
printf("\nSorry please input!\n");
j=1;
}
if(j==0) break;
}
printf("input age:");
scanf("%d", &age);
printf("input english:");
scanf("%d", &english);
printf("input math:");
scanf("%d", &math);
printf("input computer:");
scanf("%d", &computer);
ge=ge+1;
s -> num = num;
s -> english = english;
s -> math = math;
s -> computer = computer;
s -> age = age;
s -> next = p -> next;
p -> next = s;
}
return (head);
}
Student* Delete_Student (Student *head)
{
Student *p, *s;
int i;
printf("input yao Delete num:");
scanf("%d", &i);
p = Find_Student(head, i - 1);
if ((p != NULL) && (p -> next != NULL))
{
s = p -> next;
p -> next = s -> next;
free(s);
}
else
{
printf("bu cheng zai %d ge !\n", i);
return 0;
}
ge=ge-1;
return (head);
}
int LocateName_Student (Student *head)
{
Student *p;
char input;
char siName[20], diName[20];
int count = 0, j = 0, num;
p = head;
getchar();
printf("input zhao name:");
while ((input = getchar()) != '\n')
{
siName[count] = input;
count++;
}
siName[count] = '\0';
while ((p -> next != NULL) && (strcmp(siName, p -> name) != 0))
{
p = p -> next;
j++;
}
if (strcmp(siName, p -> name) == 0)
{
printf("xue sheng xingxi:\n");
printf("number\tnum\tname\tsex\tenglish-math-computer\tage\n");
printf("(%d)\t%4d\t%s\t%s\t%d-%d-%d\t%2d\n\n", j, p -> num,
p -> name, p -> sex,p -> english, p -> math,
p -> computer, p -> age);
}
else
{
printf("\nSorry!\n");
return 0;
}
}
int LocateNum_Student (Student *head, int i)
{
Student *p;
int j = 0;
p = head;
while ((p -> next != NULL) && (p -> num != i))
{
p = p -> next;
j++;
}
if (p -> num == i)
{
printf("xue sheng xingxi:\n");
printf("number\tnum\tname\tsex\tenglish-math-computer\tage\n");
printf("(%d)\t%4d\t%s\t%s\t%d-%d-%d\t%2d\n\n", j, p -> num,
p -> name, p -> sex,p -> english, p -> math,
p -> computer, p -> age);
}
else
{
printf("\nSorry!\n");
return 0;
}
}
int chengji()
{/*Student *p;
p= (Student *) malloc (sizeof(Student));*/
int j;
for(j=1;j<4;j++)
{
printf("zhong cheng ji wei:%f pingjunfeng:%f\n",zhonfen[j],pinjunf[j]);
}
}
int zhongfen()
{int j;
float kkk,pingjun,sss;
kkk=0;sss=0;
for(j=0;j<=ge;j++)
{
kkk=kkk+zhonfen[j];
sss=sss+pinjunf[j];
}
pingjun=sss/ge;
printf("zhong cheng ji wei:%f pingjunfeng:%f\n",kkk,pingjun);
}
/*
int findmax(Student *head)
{ struct student *p;
int i,temp=0;
float max;
for(max=head->zfen,i=1;i<ge;i++)
if(head->zfen>max)
{max=head->zfen;temp=i;}
p=head+temp;
printf("\nThe max mum zfen:\n");
printf("No: name: sex: age: english: math: computer: zfen:\n");
printf("%d %s %s %d %d %d %d %d",p->num,p->name,p->sex,p->age,p->english,p->math,p->computer);
}
int findmin(Student *head)
{
int i,temp=0;
float min;
for(min=head->zfen,i=1;i<15;i++)
if(head->zfen<min)
{min=head->zfen;temp=i;}
head=head+temp;
printf("\nThe min mum zfen:\n");
printf("No: name: sex: money: english: math: computer: zfen:\n");
printf("%d %s %s %d %d %d %d %d",head->num,head->name,head->sex,head->age,head->english,head->math,head->computer);
}
*/
int suxue(Student *head)
{int i,aaa,bbb,ccc,ddd,eee;
aaa=0;
bbb=0;
ccc=0;
ddd=0;
eee=0;
for(i=1;i<4;i++)
{if(head->math>=90) aaa=aaa+1;
if(head->math>=80 && head->math<90) bbb=bbb+1;
if(head->math>=70 && head->math<80) ccc=ccc+1;
if(head->math>=60 && head->math<70) ddd=ddd+1;
if(head->math<60) eee=eee+1;}
printf("90 yi shang you %d",aaa);
printf("80--90 you %d",aaa);
printf("70--80 you %d",aaa);
printf("60--70 you %d",aaa);
printf("60 yi xia you %d",aaa);
}
int yiyu(Student *head)
{int i,aaa,bbb,ccc,ddd,eee;
aaa=0;
bbb=0;
ccc=0;
ddd=0;
eee=0;
for(i=1;i<4;i++)
{if(head->english>=90) aaa=aaa+1;
if(head->english>=80 && head->english<90) bbb=bbb+1;
if(head->english>=70 && head->english<80) ccc=ccc+1;
if(head->english>=60 && head->english<70) ddd=ddd+1;
if(head->english<60) eee=eee+1;}
printf("90 yi shang you %d",aaa);
printf("80--90 you %d",aaa);
printf("70--80 you %d",aaa);
printf("60--70 you %d",aaa);
printf("60 yi xia you %d",aaa);
}
int jisuanji(Student *head)
{int i,aaa,bbb,ccc,ddd,eee;
aaa=0;
bbb=0;
ccc=0;
ddd=0;
eee=0;
for(i=1;i<4;i++)
{if(head->computer>=90) aaa=aaa+1;
if(head->computer>=80 && head->computer<90) bbb=bbb+1;
if(head->computer>=70 && head->computer<80) ccc=ccc+1;
if(head->computer>=60 && head->computer<70) ddd=ddd+1;
if(head->computer<60) eee=eee+1;}
printf("90 yi shang you %d",aaa);
printf("80--90 you %d",aaa);
printf("70--80 you %d",aaa);
printf("60--70 you %d",aaa);
printf("60 yi xia you %d",aaa);
}
这是我编写的,但是时间问题还有两个功能没有实现,我这里运行是完全可以的