int main(void)
{
char a[M];
int b[N];
FILE *fp;
int i, j, k;
int temp;
int x;
printf("Enter months please:");
for(i=0;i<M;i++)
scanf("%c", &a[i]);
printf("Your input is:");
for(i=0;i<M;i++)
printf("%c", toupper(a[i]));
printf("\n");
printf("Enter number of housing please:\n");
for(j=0;j<N;j++)
scanf("%d", &b[j]);
printf("\n");
printf("Your input is:\n");
for(j=0;j<N;j++)
printf("%d\n", b[j]);
printf("\n");
printf("Make it together like this:\n");
for(k=0;k<=5;k++)
printf("%c %d\n", toupper(a[k]), b[k]);
printf("\n");
fp=fopen("file.txt", "w");
for(k=0;k<=5;k++)
fprintf(fp, "%c %d\n", a[k], b[k]);
fclose(fp);
printf("After saved into the file and sort from highest to low\n");
printf("then OUTPUT will be:\n");
for(j=0;j<N-1;j++)
for(x=0;x<N-j-1;x++)
if(b[x]<b[x+1])
{
temp=b[x];
b[x]=b[x+1];
b[x+1]=temp;
}
for(j=0;j<N;j++)
printf("%d\n", b[j]);
fp=fopen("file.txt", "w+");
for(k=0;k<=5;k++)
fprintf(fp, "%c %d\n", a[k], b[k]);
fclose(fp);
printf("\n");
return 0;
}
Assignment Arrays Answers
最新推荐文章于 2023-06-27 09:16:38 发布