要求用户为表格输入一个下限和上限,但要设置限制,使输入保持在0和50之间。使用一个for循环但我不清楚怎么让这个上下限放进for循环
#include<stdio.h>
#include<conio.h>
#include <math.h>
int main(void)
{
// input value
int num, lower, upper;
double squareroot;
int square;
int cube;
printf("enter your number:\n");
scanf_s("%d", &num);
//set the limit for table
printf("the lower value limit is ");
scanf_s("%d", &lower);
printf("the upper value limit is ");
scanf_s("%d", &upper);
// the formular to find the squareroot, square, cube
squareroot = sqrt(num);
square = num * num;
cube = num * num * num;
//a for loop
for (num = 0; num < 51; num++) {
printf("*square root* || *square* || *cube*");
printf("*%f* || *%ld* || *%ld*", squareroot, square, cube);
}
return 0;
运行结果及不能很整齐而且没能限制一个范围
我的解答思路和尝试过的方法
最后的运行结果想显示一个表格就像这样的
平方根 | 平方 | 立方
4:2 | 16 | 64