tainqing 发表于 2017-12-2 01:02:11

C说话经典算法77-86

【法式77】
标题:填空操练(指向指针的指针)
1.法式剖析:
2.法式源代码:
main()
{ char *s[]={"man","woman","girl","boy","sister"};
char **q;
int k;
for(k=0;k<5;k++)
{ ;/*这里填写什么语句*/
printf("%s\n",*q);
}
}
==============================================================
【法式78】
标题:找到年纪最年夜的人,并输出。请找出法式中有什么题目。
1.法式剖析:
2.法式源代码:
#define N 4
#include "stdio.h"
static struct man
{ char name;
int age;
} person={"li",18,"wang",19,"zhang",20,"sun",22};
main()
{struct man *q,*p;
int i,m=0;
p=person;
for (i=0;i{if(mage)
q=p++;
m=q->age;}
printf("%s,%d",(*q).name,(*q).age);
}
==============================================================
【法式79】
标题:字符串排序。
1.法式剖析:
2.法式源代码:
main()
{
char *str1,*str2,*str3;
char swap();
printf("please input three strings\n");
scanf("%s",str1);
scanf("%s",str2);
scanf("%s",str3);
if(strcmp(str1,str2)>0) swap(str1,str2);
if(strcmp(str1,str3)>0) swap(str1,str3);
if(strcmp(str2,str3)>0) swap(str2,str3);
printf("after being sorted\n");
printf("%s\n%s\n%s\n",str1,str2,str3);
}
char swap(p1,p2)
char *p1,*p2;
{
char *p;
strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);
}
==============================================================
【法式80嵌进式信盈达企鹅要妖气鼓鼓呜呜吧久零就要】
标题:海滩上有一堆桃子,五只山公来分。第一只山公把这堆桃子根据分为五份,多了一个,这只
山公把多的一个扔进海中,拿走了一份。第二只山公把剩下的桃子又均匀分成五份,又多了
一个,它同样把多的一个扔进海中,拿走了一份,第三、第四、第五只山公都是如许做的,
问海滩上本来起码有几多个桃子?
1.法式剖析:
2.法式源代码:
main()
{int i,m,j,k,count;
for(i=4;i<10000;i+=4)
{ count=0;
m=i;
for(k=0;k<5;k++)
{
j=i/4*5+1;
i=j;
if(j%4==0)
count++;
else
break;
}
i=m;
if(count==4)
{printf("%d\n",count);
break;}
}
}
【法式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;int n;
p=s;
gets(p);
n=0;
while(*(p)!='\0')
{n=n*8+*p-'0';
p++;}
printf("%d",n);
}
==============================================================
【法式83】
标题3庠痼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,*p;
int i=0,j=0,k=0;
while(a<i>!='\0'&&b!='\0')
{if (a<i> { c=a<i>;i++;}
else
c=b;
k++;
}
c='\0';
if(a<i>=='\0')
p=b+j;
else
p=a+i;
strcat(c,p);
puts(c);
}
页: [1]
查看完整版本: C说话经典算法77-86