c语言编程问题: printf("%4d",a[i][j]);里面的数字4是起什么作用的?

 我来答
天罗网17
2022-10-12 · TA获得超过6180个赞
知道小有建树答主
回答量:306
采纳率:100%
帮助的人:72.4万
展开全部

c语言编程问题: printf("%4d",a[i][j]);里面的数字4是起什么作用的?

起到固定位数的输出格式。如果该整数小于四位,前面会输出空格
保证四位输出格式,如果该整数大于四位,按正常输出

4 是数组a元素的格式总占4个字符,不够左边加空字符

c语言编程小问题 printf("a=%d",300);输出是什么

%d 代表的是输出的时候以整型输出,a= 原样输出。
这句话的意思呢,就是说吧后边的数字格式化成整型的,也就是后边的(300)
所以:最后输出结果应该是: a=300

printf("%4d",a[m][i][j]);用VB语言怎么表示

void main()
{
int a,b,c,all;
printf("请输入年月日");
scanf("%d%d%d",&a,&b,&c);
if(b==1)
all=c;
if(b==2)
all=31+c;
if(b==3)
all=31+28+c;
if(b==4)
all=31+28+30+c;
if(b==5)
all=c+28+31*2+30;
if(b==6)
all=c+28+31*2+30*2;
if(b==7)
all=c+28+31*3+30*2;
if(b==8)
all=c+28+31*4+30*2;
if(b==9)
all=c+28+31*4+30*3;
if(b==10)
all=c+28+31*5+30*3 ;
if(b==11)
all=c+28+31*5+30*4;
if(b==12)
all=c+28+31*6+30*4;
if(((a%4==0)&&(a%100!=0)||(a%400==0))&&(b>=3) )
all++;
printf("是这一年的第%d天",all);
}
另外,团IDC网上有许多产品团购,便宜有口碑

c语言编程问题,数字直角三角形

main()
{
int i, j, k = 1;
for( j=1 ; j<=4 ; j++ )
{
for( i=1 ; i<=j ; i++ )
{
if(k==10)
k=0;
printf("%d"k++);
}
printf("\n");
}
}

c语言编程问题 数制转换

#include<stdio.h>
#include<math.h>
long NTOD(long n) /*5进制转换成10进制*/
{
long s;
int i=0;
s=n%10;
while(n!=0){
n=(long)ceil((n-n%10)/10);
i++;
s+=(((long)pow(5,i))*(n%10));
}
return s;
}
int main()
{
long n,m;
do{printf("input a number base 5:\n");
m=scanf("%ld",&n);
printf("%ld\n",NTOD(n));
}while(m);
return 0;
}

C语言编程问题:得票统计

/*在Win_TC软件中编译通过,输入人名按回车键进行投票,输入“result”按回车键查看结果*/
/*By gangjia*/
#include "stdio.h"
#include <string.h>
main()
{
char People_First[] = {"liu"}; /*候选人1*/
char People_Second[] = {"zhang"}; /*候选人2*/
char People_Third[] = {"wang"}; /*候选人3*/
char Result[] = {"result"};
char People_Temp[20];
int PFirst = 0,PScond = 0,PThird = 0;
while(1)
{
printf("Please input the name:\n"); /*输入候选人姓名*/
scanf("%s",&People_Temp);
if(strcmp(People_Temp,People_First)==0)
{ /*候选人1得票统计*/
PFirst++;
}
if(strcmp(People_Temp,People_Second)==0)
{
PScond++; /*候选人2得票统计*/
}
if(strcmp(People_Temp,People_Third)==0)
{ /*候选人3得票统计*/
PThird++;
}
if(strcmp(People_Temp,Result)==0)
{
printf("\nliu: %d",PFirst);
printf("\nzhang: %d",PScond);
printf("\nwang: %d",PThird);
break;
}
}
getch();
}

C语言编程问题,请用链表哦

看下资料书吧

C语言编程问题 有分加 请进.

/*by HHH*/
#include "stdio.h"
#include "stdlib.h"
#define N 4
struct stu
{
char name[20]; /*姓名*/
long number; /*学号*/
float grade[4]; /*三科成绩*/
};
main()
{
void input (struct stu students[],int n); /*函数声明*/
void average (struct stu students[],int n);
void inorder (struct stu students[],int n);
void output (struct stu students[],int n);
void collect (struct stu students[],int n);
struct stu stud[N];
float row[3];
input (stud,N);
average(stud,N);
inorder(stud,N);
output (stud,N);
collect(stud,N);
}
void input(struct stu students[],int n)
{
int i,j,m;
char temp[30];
for(i=0;i<n;i++)
{
printf("\ninput name,number,english,mathema,physic\n");
gets(students[i].name);
/* gets(temp); */
for(m=0;m<=4;m++)
{
students[0].number=42104101;
students[m+1].number=students[m].number+1;
}
/* students[i].number=atol(temp); */
for(j=0;j<3;j++)
{
gets(temp); /*输入三科成绩*/
students[i].grade[j]=atoi(temp);
}
}
}
/* 求各学生的三科平均成绩*/
void average(struct stu students[],int n)
{
int i,j;
for(i=0;i<n;i++) /*n个学生*/
{
students[i].grade[3]=0;
for(j=0;j<3;j++)
students[i].grade[3]=students[i].grade[3]+students[i].grade[j];
students[i].grade[3]=students[i].grade[3]/3;
}
}
/*按平均成绩排序,排序算法采用冒泡法*/
void inorder(struct stu students[],int n)
{
struct stu temp;
int i,j,x,y;
for(i=0;i<n-1;i++)
for(j=0;j<n-1;j++)
if(students[j].grade[3]>students[j+1].grade[3])
{
temp=students[j];
students[j]=students[j+1];
students[j+1]=temp;
}
}
/*按表格形式输出*/
void output(struct stu students[],int n)
{
int i,j;
printf("**************TABLE*****program*by*HHH***********************\n");
printf("-------------------------------------------------------------\n");
printf("|%10s|%8s|%7s|%7s|%7s|%7s|\n","name","number","english","mathema","physics","averageage");
printf("-------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("|%10s|%8ld|",students[i].name,students[i].number); /*输出姓名 学号*/
for(j=0;j<4;j++)
printf("%7.2f",students[i].grade[j]); /* 输出三科成绩及三科的平均*/
printf("\n");
printf("-------------------------------------------------------------\n");
}
}
/*求学生单科平均成绩并输出。在输出表格的最后一行,输出单科平均成绩及总平均*/
void collect(struct stu students[],int n)
{
float row[4]={0,0,0,0}; /*存放单项平均 */
int i,j;
for(i=0;i<n;i++)
{
for (j=0;j<n;j++)
row[i]=row[i]+students[j].grade[i];
row[i]=row[i]/n; /*计算单项平均 */
}
printf("|%19c|",''); /*按表格形式输出 */
for(i=0;i<4;i++)
printf("%7.2f",row[i]);
printf("\n-------------------------------------------------------------\n");
getch();
}

C语言编程问题,请朋友帮忙!

在TC上调试成功
实现了追加、显示、删除、查找功能;删除功能用c语言不好实现,我采用的是创建一个临时文件,把除符合条件以外的记录都拷贝过去,然后再拷贝回来,最后删除临时文件。
#include "stdio.h"
struct student
{
char name[20];
float score [4];
}stu;
char filename[20]="myfile";
append(char *filename)
{
char ch;
FILE *fp;
fp=fopen(filename,"a");
do{
printf("\nplease input the student's data you want to append:\n");
scanf("%s%f%f%f%f",stu.name,&stu.score[0],&stu.score[1],&stu.score[2],&stu.score[3]);
fseek(fp,0,2);
fwrite(&stu,sizeof(struct student),1,fp);
printf("\ndo you want to continue appending?(y/n)");
getchar();
ch=getchar();
}while(ch!='n');
fclose(fp);
}
list(char *filename)
{
FILE *fp;
fp=fopen(filename,"r");
printf("\nname s1 s2 s3 s4");
printf("\n**************************************");
while(fread(&stu,sizeof(struct student),1,fp)==1)
{
printf("\n%-10s%7.2f%7.2f%7.2f%7.2f",stu.name,stu.score[0],stu.score[1],stu.score[2],stu.score[3]);
}
fclose(fp);
}
seek(char *filename,char *stu_name)
{
FILE *fp;
int s;
fp=fopen(filename,"r");
printf("\n\nname s1 s2 s3 s4");
printf("\n**************************************");
s=fread(&stu,sizeof(struct student),1,fp);
while(s==1)
{
if (strcmp(stu.name,stu_name)==0)
{printf("\n%-10s%7.2f%7.2f%7.2f%7.2f",stu.name,stu.score[0],stu.score[1],stu.score[2],stu.score[3]);}
s=fread(&stu,sizeof(struct student),1,fp);
}
fclose(fp);
}
del(char *filename,char *del_name)
{
FILE *fp;
FILE *temp;
int s;
temp=fopen("temp","w");
fp=fopen(filename,"a+");
s=fread(&stu,sizeof(struct student),1,fp);
while(s==1)
{
if (strcmp(stu.name,del_name)!=0)
fwrite(&stu,sizeof(struct student),1,temp);
s=fread(&stu,sizeof(struct student),1,fp);
}
fclose(fp);
remove(filename);
fp=fopen(filename,"w");
rewind(temp);
s=fread(&stu,sizeof(struct student),1,temp);
while(s==1)
{
fwrite(&stu,sizeof(struct student),1,fp);
s=fread(&stu,sizeof(struct student),1,temp);
}
fclose(fp);
fclose(temp);
remove("temp");
}
main()
{
char stu_name[20],del_name[20];
append(filename);
list(filename);
while (strcmp(stu_name,"quit")!=0)
{
printf("\nplease input the student's name you want to search:(input \"quit\" to exit)");
scanf("%s",stu_name);
seek(filename,stu_name);
}
while (strcmp(del_name,"quit")!=0)
{
printf("\nplease input the student's name you want to delete:(input \"quit\" to exit)");
scanf("%s",del_name);
del(filename,del_name);
list(filename);
}
}

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式