问题描述
我没有得到输出。请使用代码帮助我。这是一个程序,用于打印小于或等于给定整数的所有数字中存在的总数。
例如如果n = 10
则1,2,3,4,5,6,7,8,9,10
输出为2,即总数为2
我尝试过:
#include< iostream>
使用命名空间std;
int nuz(int num)
{int i,count = 0;
for (i = 1; i< = num; i ++)
{while(i> 0)
{if(i%10 == 1)
{count ++;
num = num / 10;
}}}
返回计数;}
int main()
{int x,c;
cout<<输入否;
cin>> x;
c = nuz(x);
cout<<零是<< c;
返回0;
}
I am not getting the output.Help me with code.This is a program to print the total number of ones present in the all numbers less than or equal to a given integer.
for example if n=10
then 1,2,3,4,5,6,7,8,9,10
output is 2 that is total one's are 2
What I have tried:
#include <iostream>
using namespace std;
int nuz(int num)
{int i,count=0;
for(i=1;i<=num;i++)
{while(i>0)
{if(i%10==1)
{count++;
num=num/10;
}}}
return count;}
int main()
{int x,c;
cout<<"enter no";
cin>>x;
c=nuz(x);
cout<<"zeroes are"<<c;
return 0;
}
推荐答案
}}}
我开始颤抖,真的不想看在它任何进一步!我知道你只是一个初学者,但是从一开始就学习好的做法 - 他们会让你的工作变得更轻松!
I start to shudder and really don't want to look at it any further! I know you are only a beginner, but learn good practices to start with - they will make your job a whole lot easier!
#include <iostream>
using namespace std;
int nuz(int num)
{
int i,count=0;
for(i=1;i<=num;i++)
{
while(i>0)
{
if(i%10==1)
{
count++;
num=num/10;
}
}
}
return count;
}
int main()
{
int x,c;
cout<<"enter no";
cin>>x;
c=nuz(x);
cout<<"zeroes are"<<c;
return 0;
}
专业程序员的编辑器具有此功能,其他功能包括括号匹配和语法高亮。
[]
[]
-----
有一个工具可以让你要查看代码正在执行的操作,其名称为调试程序。它也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪种期望与现实相符。
当你不明白你的代码在做什么或为什么它做它做的时候,答案就是答案是调试器。
使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。
[]
[]
[]
调试器在这里向您展示您的代码正在做什么,您的任务是与什么进行比较应该这样做。
调试器中没有魔法,它没有找到错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
-----
There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
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.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
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.
这篇关于如何获得我在下面提到的程序输出。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!