解释这段代码void present()//显示所有 { int i; if (n == 0) { printf("您好,现在没有学生信息,请先增加学生信息或者刷新再来试试!\n"); } else { printf("现在共有%d名学生:\n", n); printf("学号\t\t姓名\t\t性别\t\t年龄\t\tC语言\t\t高数\t\t英语\n"); for (i = 0; i < n; i++) { printf("%s\t\t%s\t\t%c\t\t%d\t\t%.2f\t\t%.2f\t\t%.2f\n", stu[i].StuID, stu[i].Stuname, stu[i].Stusex, stu[i].Stuage, stu[i].score[0], stu[i].score[1], stu[i].score[2]); } } system("pause"); }
时间: 2023-08-22 08:09:14 浏览: 101
这是一个用于显示学生信息的函数。它首先判断学生信息是否为空,如果为空则输出提示信息,否则就输出所有学生的信息。具体的信息包括每个学生的学号、姓名、性别、年龄以及C语言、高数和英语的成绩。其中,stu数组是一个结构体数组,包含了所有学生的信息。函数最后使用system("pause")来暂停程序,等待用户按下任意键后继续执行程序。
相关问题
C语言代码输出排版调整void present() //浏览函数 { int i; if(n==0) { printf("您好,现在没有学生信息,请先增加学生信息!\n"); } else { printf("现在共有%d名学生:\n",n); printf("学号\t\t\t姓名\t\t性别\t\t班级\t\t\t出生日期\t\t 电话\t\t 家庭地址\t\t\t C语言成绩\t\t高数成绩\t大学英语成绩\n"); for(i=0;i<n;i++) { printf("%s\t\t%s\t\t%s\t\t%s\t\t\t%s\t\t%s\t\t%s\t\t%.2f\t\t%.2f\t\t%.2f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].banji,stu[i].brith,stu[i].phonenumber,stu[i].home,stu[i].score[0],stu[i].score[1],stu[i].score[2]); } } system("pause"); }
以下是排版调整后的 C 语言代码:
void present() //浏览函数
{
int i;
if (n == 0)
{
printf("您好,现在没有学生信息,请先增加学生信息!\n");
}
else
{
printf("现在共有 %d 名学生:\n", n);
printf("学号\t\t\t姓名\t\t性别\t\t班级\t\t\t出生日期\t\t 电话\t\t 家庭地址\t\t\t C语言成绩\t\t高数成绩\t大学英语成绩\n");
for (i = 0; i < n; i++)
{
printf("%s\t\t%s\t\t%s\t\t%s\t\t\t%s\t\t%s\t\t%s\t\t%.2f\t\t%.2f\t\t%.2f\n", stu[i].num, stu[i].name, stu[i].sex, stu[i].banji, stu[i].brith, stu[i].phonenumber, stu[i].home, stu[i].score[0], stu[i].score[1], stu[i].score[2]);
}
}
system("pause");
}
解释这段代码#include <stdio.h> #include<unistd.h> #include<time.h> #include<stdlib.h> struct pl_type { int pn,pfn,time; }; struct pfc_struct { int pn,pfn; struct pfc_struct * next; }; int s[320]; struct pl_type pl[32]; struct pfc_struct pfc[32]; struct pfc_struct * freepf_head; void initial(int pf); void lru(int pf); int main() { int i,total_pf; srand(getpid()); for(i=0;i<320;i++) { s[i]=rand()%32; } for(total_pf=4;total_pf<=32;total_pf++) { initial(total_pf); lru(total_pf); } return 0; } void initial(int pf) { int i; for(i=0;i<32;i++) { pl[i].pn=i; pl[i].pfn=-1; pl[i].time=0; } for(i=0;i<pf-1;i++) { pfc[i].pfn=i; pfc[i].next=&pfc[i+1]; } pfc[pf-1].pfn=pf-1; pfc[pf-1].next=NULL; freepf_head=&pfc[0]; } void lru(int pf) { int i,j,diseffect=0; /*diseffect用来记录页面失效次数*/ int mintime,minj,present_time; /*present_time用于计时*/ for(i=0;i<320;i++) /*处理页面访问序列,计算失效数*/ { if(pl[s[i]].pfn==-1) /*被访问页面不在内存中,失效数加1并将其调入内存*/ { diseffect+=1; if(freepf_head==NULL) /*无空闲帧,则找出距现在最久的被访问页,并将淘汰,将其占用的帧加入空闲帧队列*/ { mintime=32767; for(j=0;j<32;j++) { if(mintime>pl[j].time&&pl[j].pfn!=-1) { mintime=pl[j].time; minj=j; } } freepf_head=&pfc[pl[minj].pfn]; pl[minj].pfn=-1; pl[minj].time=-1; freepf_head->next=NULL; } pl[s[i]].pfn=freepf_head->pfn; /*为待调入页面分配一帧,并记录下访问时间*/ pl[s[i]].time=present_time; freepf_head=freepf_head->next; } else pl[s[i]].time=present_time; /*若被访页面在内存中则更新访问时间*/ present_time++; /*每处理页面访问序列中的一项,计时器加1*/ } printf("%d frames %f\n",pf,1-(float)diseffect/320); }
这段代码是一个简单的页面置换算法 LRU(最近最少使用)的模拟实现。它模拟了一个大小为 32 的物理内存和一个大小为 320 的虚拟地址序列,对于每个物理内存大小从 4 到 32 不等的情况,程序计算了在 LRU 算法下的缺页率,并输出结果。具体实现过程中,程序会先进行一些初始化工作,如初始化物理内存和空闲帧队列,并记录虚拟地址序列访问时间。然后程序按照虚拟地址序列模拟访问过程,对于每个页面访问,如果它不在物理内存中,则会将其从磁盘中读入内存,并选择一个最久未被使用的页面进行淘汰。如果物理内存中有空闲帧,则直接使用空闲帧。最后程序输出缺页率的计算结果。
阅读全文
相关推荐
















