【程序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(&quot;%d&quot;,&a);
}while(a<1||a>50);
for(i=1;i<=a;i++)
printf(&quot;*&quot;);
printf(&quot;\n&quot;);
n++;}
getch();
}
==============================================================
【程序89】
题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:
每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。
1.程序分析:
2.程序源代码:
main()
{int a,i,aa[4],t;
scanf(&quot;%d&quot;,&a);
aa[0]=a ;
aa[1]=a 0/10;
aa[2]=a 00/100;
aa[3]=a/1000;
for(i=0;i<=3;i++)
{aa+=5;
aa%=10;
}
for(i=0;i<=3/2;i++)
{t=aa;
aa=aa[3-i];
aa[3-i]=t;
}
for(i=3;i>=0;i--)
printf(&quot;%d&quot;,aa);
}
==============================================================
【程序90】
题目:专升本一题,读结果。
1.程序分析:
2.程序源代码:
#include &quot;stdio.h&quot;
#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(&quot;%d&quot;,*(a+i));
}
【程序91】
题目:时间函数举例1
1.程序分析:
2.程序源代码:
#include &quot;stdio.h&quot;
#include &quot;time.h&quot;
void main()
{ time_t lt; /*define a longint time varible*/
lt=time(NULL);/*system time and date*/
printf(ctime(<)); /*english format output*/
printf(asctime(localtime(<)));/*tranfer to tm*/
printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/
}
==============================================================
【程序92】
题目:时间函数举例2
1.程序分析:
2.程序源代码:
/*calculate time*/
#include &quot;time.h&quot;
#include &quot;stdio.h&quot;
main()
{ time_t start,end;
int i;
start=time(NULL);
for(i=0;i<3000;i++)
{ printf(&quot;\1\1\1\1\1\1\1\1\1\1\n&quot;);}
end=time(NULL);
printf(&quot;\1: The different is %6.3f\n&quot;,difftime(end,start));
}
==============================================================
【程序93】
题目:时间函数举例3
1.程序分析:
2.程序源代码:
/*calculate time*/
#include &quot;time.h&quot;
#include &quot;stdio.h&quot;
main()
{ clock_t start,end;
int i;
double var;
start=clock();
for(i=0;i<10000;i++)
{ printf(&quot;\1\1\1\1\1\1\1\1\1\1\n&quot;);}
end=clock();
printf(&quot;\1: The different is %6.3f\n&quot;,(double)(end-start));
}
==============================================================
【程序94】
题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)
1.程序分析:
2.程序源代码:
#include &quot;time.h&quot;
#include &quot;stdlib.h&quot;
#include &quot;stdio.h&quot;
main()
{char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf(&quot;do you want to play it.('y' or 'n') \n&quot;);
loop:
while((c=getchar())=='y')
{
i=rand() 0;
printf(&quot;\nplease input number you guess:\n&quot;);
start=clock();
a=time(NULL);
scanf(&quot;%d&quot;,&guess);
while(guess!=i)
{if(guess>i)
{printf(&quot;please input a little smaller.\n&quot;);
scanf(&quot;%d&quot;,&guess);}
else
{printf(&quot;please input a little bigger.\n&quot;);
scanf(&quot;%d&quot;,&guess);}
}
end=clock();
b=time(NULL);
printf(&quot;\1: It took you %6.3f seconds\n&quot;,var=(double)(end-start)/18.2);
printf(&quot;\1: it took you %6.3f seconds\n\n&quot;,difftime(b,a));
if(var<15)
printf(&quot;\1\1 You are very clever! \1\1\n\n&quot;);
else if(var<25)
printf(&quot;\1\1 you are normal! \1\1\n\n&quot;);
else
printf(&quot;\1\1 you are stupid! \1\1\n\n&quot;);
printf(&quot;\1\1 Congradulations \1\1\n\n&quot;);
printf(&quot;The number you guess is %d&quot;,i);
}
printf(&quot;\ndo you want to try it again?(\&quot;yy\&quot;.or.\&quot;n\&quot;)\n&quot;);
if((c=getch())=='y')
goto loop;
} |