我是编码的初学者,并试图完成我的作业.
虽然我已经解决了我的问题,但是在这样做时我偶然发现了\ t的意外行为.我得到单个\ t的不同标签长度.这是我的代码:
#include<stdio.h>
int calculate_intpart_qutent(int dividend, int diviser);
int main()
{
int a;
int b;
int choice;
do
{
printf("Enter the Dividend (a) :\t");
scanf("%d", &a);
printf("\nEnter the Divisor (b) :\t");
scanf("%d", &b);
printf("\n\nThe quotient is:\t%d", calculate_qutent(a, b));
printf("\n\nDo you want to try again?(Y\\N):\t");
choice = getchar();
if (choice == '\n') choice = getchar();
printf("\n\n\n");
} while (choice=='y'|| choice=='Y');
}
int calculate_intpart_qutent(int dividend, int diviser)
{
return (dividend/diviser);
}
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
由于我在两个第一个printf语句中都使用了单选项卡,为什么我在输出屏幕上获得不同的选项卡长度?我在这里做错了什么?
在你投票并埋葬这个问题之前,请考虑我是C的初学者.任何帮助都感激不尽.
我正在使用Visual Studio 2017 RC.
我写了这个简单的程序,它应该计算用户输入的数字的阶乘。程序应该要求用户停止或继续程序以找到新数的阶乘。
由于大多数时候用户不注意 CapsLock,程序应该接受 Y 或 y 作为是的答案。但是每次我运行这个程序时,即使我输入 Y/y ,它也会被终止!
我用谷歌搜索并发现问题可能是由于new line字符被我的字符输入所接受,所以我修改了 scanf 代码从scanf("%c", &choice);toscanf("%c ", &choice);以适应新行字符,但我的程序在接受 Y/y 作为输入后仍然被终止.
这是代码。如果可能,请让我知道处理此类问题的最佳实践和方法以及所需的更正。
#include<stdio.h>
#include"Disablewarning.h" // header file to disable s_secure warning in visual studio contains #pragma warning (disable : 4996)
void main() {
int factorial=1;//Stores the factorial value
int i; //Counter
char choice;//stores user choice to continue or terminte the program
do {//Makes sure the loop isn't terminated until the user decides
do{
printf("Enter the no whose …Run Code Online (Sandbox Code Playgroud)