Loops 如何打印未知数量的结果?
第一次发布,也是C语言的初学者。我的问题是如何打印数量未知的结果?以这段代码为例:Loops 如何打印未知数量的结果?,loops,scanf,printf,Loops,Scanf,Printf,第一次发布,也是C语言的初学者。我的问题是如何打印数量未知的结果?以这段代码为例: #include <stdio.h> int main(void) { int a,b,c; b=0; printf("Enter the number of terms: "); scanf("%d", &a); for(b=0; b<=a; ++a) { printf("\n\nEnter the value of
#include <stdio.h>
int main(void)
{
int a,b,c;
b=0;
printf("Enter the number of terms: ");
scanf("%d", &a);
for(b=0; b<=a; ++a)
{
printf("\n\nEnter the value of each term: ");
scanf("%d",&c);
}
printf("\n\n%d",c);
return(0);
}
#包括
内部主(空)
{
INTA、b、c;
b=0;
printf(“输入术语编号:”);
scanf(“%d”和“&a”);
对于(b=0;b,您需要使用所谓的数组来存储数据。您可以将数组想象成一个有不同抽屉的文件柜。每个抽屉可以存储一个值,您可以通过引用其索引来访问该抽屉
您可以在此处了解有关C中阵列的所有信息:
祝你好运
编辑:以下是fprintf的一个示例:
/* fprintf example */
#include <stdio.h>
int main ()
{
FILE * pFile;
int n;
char name [100];
pFile = fopen ("myfile.txt","w");
for (n=0 ; n<3 ; n++)
{
puts ("please, enter a name: ");
gets (name);
fprintf (pFile, "Name %d [%-10.10s]\n",n,name);
}
fclose (pFile);
return 0;
}
/*fprintf示例*/
#包括
int main()
{
文件*pFile;
int n;
字符名[100];
pFile=fopen(“myfile.txt”,“w”);
对于(n=0;n感谢您的评论和帮助。我不知道我是否可以使用数组,因为我还没有在课堂上学习过数组,但我仍然会在您建议的网站上阅读。问题是,我需要知道一个项目。如果您知道使用fprintf的其他方法,那将非常感谢。我个人没有使用fprintf,但它看起来与printin有关将文件内容添加到流中?我在网上找到了一个示例,并将其添加到我的帖子中。希望它能有所帮助。