为什么这段代码不打印? [英] Why this code is not printing?
本文介绍了为什么这段代码不打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
/ *使用结构* /
#include< stdio.h>以升序打印学生标记的程序
int main()
{
int n,c,t;
printf(输入学生总人数);
scanf(%d,& n);
c = getchar();
struct student
{
char name [100];
char section;
int marks [5];
} s [n];
for(int i = 0; i< n; i ++)
{
printf(输入名称:);
得到(s [i] .name);
printf(\ n);
printf(输入部分:);
scanf(%c,& s [i] .section);
printf(\ n);
printf(在5个主题中输入标记\ n);
for(int j = 0; j< 5; j ++)
{
scanf(%d,&(s [i] .marks [j]));
}
c = getchar();
}
for(int i = 0; i< n; i ++)
{
for(int k = 0; k< 5; k ++)
{
for(int j = 0; j< 4; j ++)
{
if(s [i] .marks [j]> s [i] .marks [j + 1])
{
t = s [i] .marks [j];
s [i] .marks [j] = s [i] .marks [j + 1];
s [i] .marks [j + 1] = t;
}
}
}
}
for(int i = 0; i< n; i ++)
{
printf(\\ \
\\\
Name\tSection\\\
);
printf(%s \ t%c \ t \ n,s [i] .name,s [i] .section);
printf(标记为5个主题\ n);
for(int j = 0; j< 5; j ++)
{
printf(%d \ n,(s [i] .marks [j]));
}
}
返回0;
}
我的尝试:
此代码不打印输出,我希望用户输入5个学科和标记的学生数据和标记。程序将按升序对标记进行排序并打印数据。
解决方案
'缺失输出'可能与 IDE $相关c $ c>你正在使用。尝试在最后一个语句( return 0;
)之前调用 getchar
,以便暂停执行并查看输出
/*Program to print marks of students in ascending order using structure */ #include<stdio.h> int main() { int n,c,t; printf("Enter Total No Of Students\n"); scanf("%d",&n); c=getchar(); struct student { char name[100]; char section; int marks[5]; }s[n]; for(int i=0;i<n;i++) { printf("Enter Name :"); gets(s[i].name); printf("\n"); printf("Enter Section :"); scanf("%c",&s[i].section); printf("\n"); printf("Enter Marks In 5 Subjects \n"); for(int j=0;j<5;j++) { scanf("%d",&(s[i].marks[j])); } c=getchar(); } for(int i=0;i<n;i++) { for(int k=0;k<5;k++) { for(int j=0;j<4;j++) { if(s[i].marks[j]>s[i].marks[j+1]) { t=s[i].marks[j]; s[i].marks[j]=s[i].marks[j+1]; s[i].marks[j+1]=t; } } } } for(int i=0;i<n;i++) { printf("\n\nName\tSection\n"); printf("%s\t%c\t\n",s[i].name,s[i].section); printf("Marks In 5 Subjects \n"); for(int j=0;j<5;j++) { printf("%d \n",(s[i].marks[j])); } } return 0; }
What I have tried:
This code is not printing the output,I want user to enter data of students and marks in 5 subject & the program will sort marks in ascending order and print the data.
解决方案
The 'missing output' is probably related to theIDE
you are using. Try to put agetchar
call just before the last statement (return 0;
) in order to pause execution and see the output.
这篇关于为什么这段代码不打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文