问题8:
输入年、月、日,输出该日期是该年的第几天。(25分)
问题9:
利用数组实现数据的存储。将学生的学号和成绩存储在数组中,利用循环计算出数组中存储学生的平均成绩,找出高于平均分的学生信息并输出。(20分)
问题10:
输入五个国家的名字,按字母顺序(即按ASCII码从小到大的顺序)排列输出。(20分)
问题11:
用指针实现:任意输入20个数,将它们按照从大到小的顺序输出。(20分)
问题7实现代码:
/*author:宋金时*/
/*date:2011/11/01*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int m_i5,m_arr[5],m_temp,i,j,m_max,m_swap;
printf("请输入一个5位整数:");
scanf("%d",&m_i5);
printf("输入的数字为:%d\n",m_i5);
m_temp = m_i5;
for(m_temp,i=0;m_temp>0;i++)
{
m_arr[i]=m_temp%10;
m_temp/=10;
}
for(i=0;i<5;i++)
{
m_max=i;
for(j=i+1;j<5;j++)
{
if(m_arr[m_max]<m_arr[j])
{
m_max=j;
}
}
if(m_max!=i)
{
m_swap=m_arr[i];
m_arr[i]=m_arr[m_max];
m_arr[m_max]=m_swap;
}
}
printf("处理过的数字为:%d\n",m_arr[0]*10000+m_arr[1]*1000+m_arr[2]*100+m_arr[3]*10+m_arr[4]);
system("PAUSE");
return 0;
}
/*author:宋金时*/
/*date:2011/11/02*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int m_year[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int years,month,days,w_day=0,i;
printf("please input years、month、days:");
scanf("%d%d%d",&years,&month,&days);
for(i=0;i<month-1;i++)
{
w_day+=m_year[i];
}
w_day+=days;
if((years%400==0||(years%4==0&&years%100!=0))&&month>=3)
w_day++;
printf("您输入的日期是%d年的第%d天\n",years,w_day);
system("PAUSE");
return 0;
}
/*author:宋金时*/
/*date:2011/11/02*/
#include "stdio.h"
#include "conio.h"
#define N 3
main()
{
int arr_num[N],i;
float m_ave=0,m_sum=0,arr_score[N];
printf("please input student's number and score: \n");
for(i=0;i<N;i++)
{
scanf("%d%f",&arr_num[i],&arr_score[i]);
m_sum+=arr_score[i];
}
m_ave=m_sum/N;
printf("number score\n");
for(i=0;i<N;i++)
{
if(arr_score[i]>m_ave)
{
printf("%d %f\n",arr_num[i],arr_score[i]);
}
}
getch();
}
/* author:宋金时 */
/*date:2011/11/02*/
#include "Stdio.h"
#include "Conio.h"
#define N 5
int main(void)
{
char arr_coutry[N][20],m_temp[20];
int m_i,m_j,m_max;
printf("please input 5 coutry name:");
for(m_i=0;m_i<N;m_i++)
{
gets(arr_coutry[m_i]);
}
for(m_i=0;m_i<N;m_i++)
{
m_max = m_i;
for(m_j=m_i+1;m_j<N;m_j++)
{
if(strcmp(arr_coutry[m_j],arr_coutry[m_max])>0)
{
m_max = m_j;
}
}
if(m_max!=m_i)
{
strcpy(m_temp,arr_coutry[m_i]);
strcpy(arr_coutry[m_i],arr_coutry[m_max]);
strcpy(arr_coutry[m_max],m_temp);
}
puts(arr_coutry[m_i]);
}
getch();
return 0;
}
/* author:宋金时 */
/* date:2011/11/02 */
#include "Stdio.h"
#include "Conio.h"
#define N 20
int main(void)
{
int arr_num[N],m_i,m_j,m_max,m_temp;
puts("please input 20
number:\n");
for(m_i=0;m_i<N;m_i++)
{
scanf("%d",&arr_num[m_i]);
}
for(m_i=0;m_i<N;m_i++)
{
m_max=m_i;
for(m_j=m_i+1;m_j<N;m_j++)
{
if(arr_num[m_j]>arr_num[m_max])
{
m_max = m_j;
}
}
if(m_max!=m_i)
{
m_temp = arr_num[m_i];
arr_num[m_i] = arr_num[m_max];
arr_num[m_max] = m_temp;
}
printf("%d ",arr_num[m_i]);
}
getch();
return 0;
}