为什么我的输出为1,其值为n = 7? [英] Why my output is 1 with value of n=7?

查看:66
本文介绍了为什么我的输出为1,其值为n = 7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用break来输入数字,直到n的值但是max = 10但是程序的输出是1,无论是什么值n



什么我试过了:



using break to input numbers till the value of n but max=10 but output of the program is 1 whatever be the value of n

What I have tried:

#include<stdio.h>
int main()
{
int i=1,n;
printf("enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    printf("%d",i);
    if(i=10)
    break;
}
}



输出


output

enter value of n7
1

推荐答案

你真的需要停止发布这些问题;这不是学习编程的方法。给自己写一本关于C或C ++的好书然后开始阅读。
You really need to stop posting these questions; this is not the way to learn programming. Get yourself a good book on C or C++ and start reading.


你真的需要拿起C / C ++上的初学者书并通过它来学习。



您还需要学习如何使用调试器,设置断点和检查变量内容。调试器用于调试您和您对代码的理解。现在,你只是猜测代码在做什么。您不了解您正在撰写的内容,并且在论坛上发布问题后无法帮助解决该问题。你绕过了实际学习。
You seriously need to pick up beginners book on C/C++ and work through it.

You also need to learn how to use the debugger, set breakpoints and inspect variable contents. The debugger is there to debug YOU and your understanding of the code. Right now, you're just guessing at what the code is doing. You have no understanding of what you're writing and posting question after question on forums is not helping solve that problem. You're bypassing actual learning.


i = 10 分配 10 变量 i

i == 10 比较 10 到变量 i

这是非常基本的C语言,你需要认真学习。



以下是语言作者对C和C ++参考书的链接。注意,C是C ++的祖先,所以知道C对C ++总是有用。

C编程语言 - 维基百科,免费的百科全书 [ ^ ]

https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2。 pdf [ ^ ]

http://www.ime.usp。 br / ~pf / Kernighan-Ritchie / C-Programming-Ebook.pdf [ ^ ]



C ++编程语言 [ ^ ]



学习使用调试器也会有所帮助。

如果你不理解你的代码在做什么或为什么它做了什么,答案是 debugger

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]



调试器在这里显示你的代码正在做什么,你的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
i=10 assign 10 to variable i and
i==10 compares 10 to variable i.
that is very basic C language, you need to learn it seriously.

Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]

C++ Programing Language[^]

Learning to use a debugger will help too.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于为什么我的输出为1,其值为n = 7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆