我将如何在每次循环迭代后打印语句? C
How Would I go about Printing a Statement after each iteration of the loop? C
我是 C 的新手,该程序的主要功能是打印用户指定整数的乘法 table。但我缺少的主要是能够打印正在打印的指定时间 table。例如,这是 1 的时间 table 这是 2 的时间 table 等。感谢您的帮助。
这是我的输出...
这是我想要达到的输出....
原始代码:
#include<stdio.h>
int main()
{
int i, j, n, z, product;
printf("Please Enter an Interger: ");
scanf("%d", &n);
//next Interger
printf("Please Enter an Interger: ");
scanf("%d", &z);
/* Generating Multiplication Table */
for(i=1;i<=n;i++)
{
for(j=1;j<=z;j++) //Nested For Loop to iterate until the second interger is met
{
product = i*j;
printf("%d x %d = %d\t", i, j, product);
}
printf("\n");
}
return(0);
}
您正在寻找这个。
#include <stdio.h>
int main()
{
int n, m, i, j, product;
printf("Enter integer: ");
scanf("%d", &n);
printf("Enter integer: ");
scanf("%d", &m);
printf("\n");
for(i=1; i<=n; i++) {
printf("* %d Times Table*\n", i); //###
for(j=1; j<=m; j++) {
product = i*j;
printf("\t%d x %d = %d\n", i, j, product); //###
}
printf("****************"); //###
printf("\n\n"); //###
}
return 0;
}
逻辑没问题,但您必须修正一下 printf 的用法。
需要一点点改变
#include<stdio.h>
int main()
{
int i, j, n, z, product;
printf("Please Enter an Interger: ");
scanf("%d", &n);
//next Interger
printf("Please Enter an Interger: ");
scanf("%d", &z);
for(i=1;i<=n;i++)
{
printf("\n*%d Times Table*",i); //statement to print before table printing
for(j=1;j<=z;j++) //Nested For Loop to iterate until the second interger is met
{
product = i*j;
printf("\n %d x %d = %d\t", i, j, product); //to print on new line
}
printf("\n");
printf("\n***********"); //* pattern as output demand
}
return(0);
}
我是 C 的新手,该程序的主要功能是打印用户指定整数的乘法 table。但我缺少的主要是能够打印正在打印的指定时间 table。例如,这是 1 的时间 table 这是 2 的时间 table 等。感谢您的帮助。
这是我的输出...
这是我想要达到的输出....
原始代码:
#include<stdio.h>
int main()
{
int i, j, n, z, product;
printf("Please Enter an Interger: ");
scanf("%d", &n);
//next Interger
printf("Please Enter an Interger: ");
scanf("%d", &z);
/* Generating Multiplication Table */
for(i=1;i<=n;i++)
{
for(j=1;j<=z;j++) //Nested For Loop to iterate until the second interger is met
{
product = i*j;
printf("%d x %d = %d\t", i, j, product);
}
printf("\n");
}
return(0);
}
您正在寻找这个。
#include <stdio.h>
int main()
{
int n, m, i, j, product;
printf("Enter integer: ");
scanf("%d", &n);
printf("Enter integer: ");
scanf("%d", &m);
printf("\n");
for(i=1; i<=n; i++) {
printf("* %d Times Table*\n", i); //###
for(j=1; j<=m; j++) {
product = i*j;
printf("\t%d x %d = %d\n", i, j, product); //###
}
printf("****************"); //###
printf("\n\n"); //###
}
return 0;
}
逻辑没问题,但您必须修正一下 printf 的用法。
需要一点点改变
#include<stdio.h>
int main()
{
int i, j, n, z, product;
printf("Please Enter an Interger: ");
scanf("%d", &n);
//next Interger
printf("Please Enter an Interger: ");
scanf("%d", &z);
for(i=1;i<=n;i++)
{
printf("\n*%d Times Table*",i); //statement to print before table printing
for(j=1;j<=z;j++) //Nested For Loop to iterate until the second interger is met
{
product = i*j;
printf("\n %d x %d = %d\t", i, j, product); //to print on new line
}
printf("\n");
printf("\n***********"); //* pattern as output demand
}
return(0);
}