在这些条件下,我如何编写C程序以生成012345678910987654321 [英] How do I write c program to generate 012345678910987654321, with these conditions

查看:302
本文介绍了在这些条件下,我如何编写C程序以生成012345678910987654321的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.输出应在20月份为正数
2.程序应仅包含一个循环或条件或三元运算符或任何其他内容
3.除1
之外,不应初始化序列中可用的任何数字 4.不应测试该系列中可用的编号(例如i< 10,i< = 5)

[更新]
我写了很多遍,如下所示

1. Output should have 20 in nombers
2. program should contain only one loop or condition or ternary operator or anything
3. shouldn''t initialize any number available in the series except 1
4. should not tested any nos available in the series (like i<10, i<=5)

[Update]
I wrote and tried many times as like below

#include <stdio.h>
#include <stdlib.h>

int main()
{
    static int i,j;
    printf("%d",i);
    for(i=1,j=1;i<11,j<(1000/100);i++,j++)
    {
        printf("%d",i);

        printf("%d",10-j);
    }
    return 0;
}

推荐答案

我们不做作业:它的设置是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,您可能会发现它并不像您想的那么难!

如果您遇到特定问题,请询问此问题,我们将尽最大努力为您提供帮助.但是我们不会为您做这一切!

因此,首先要手动进行操作,然后确定您的操作方法.
然后,您可以查看将其转换为代码.
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren''t going to do it all for you!

So start by doing it manually, and work out how you do it.
Then you can look at translating that into code.


1)仔细阅读您的课程.
2)看看它与您的运动有何关系.
3)在纸上写下您将如何使用伪代码执行操作.
4)打开您的IDE,或者根据需要打开文本编辑器.
5)根据第3点开始编写代码.
6)在某些时候,您可能会遇到困难,然后您可能会回到这里并就特定问题提出具体问题.
1) Read your course carefully.
2) See how it is related to your exercise.
3) Write down on a paper how you are going to do things in peseudo-code.
4) Open your IDE, or a text editor if you prefer.
5) Begin to code according to point 3.
6) At some point, you may experience difficulty, you may then come back here ans ask a specific question on a specific issue.


您的代码很困惑!

这是第一个更正,它为您提供所需结果的第一部分.
Your code is confused !

Here is a first correction which gives you the first part of the wanted result.
#include <stdio.h>
#include <stdlib.h>

int main() {
    static int i;
    for(i=0; i<11; i++) {
        printf("%d",i);
    }
    // Here is the place to make the second part of what you want
    return 0;
}


我让您完成结果的最后代码.

注意:始终初始化所有变量是一个好习惯.您会发现我的代码没有使用与您的代码相反的未初始化变量.

[更新]
好的,这段代码只能完成一半的工作.这是解决方案的线索:
实际代码使用f(x)= x
在下面的文本中:


I let you complete the code for the end of the result.

Nota: it is a good habit to always initialise all your variables. you see that my code don''t use uninitialised variables contrary to your code.

[Update]
Ok the piece of code do only half of the job. Here is a lead to solution:
Actual piece of code use f(x)= x
In text below:

x      -5 -4 -3 -2 -1  0  1  2  3  4  5
f(x)=x -5 -4 -3 -2 -1  0  1  2  3  4  5
?       5  4  3  2  1  0  1  2  3  4  5
?      -5 -4 -3 -2 -1  0 -1 -2 -3 -4 -5
?       5  6  7  8  9 10  9  8  7  6  5


第1行是x
的值 第2行是实际的f(x)
哪个数学函数给出第3行的结果?
什么变化使第4行产生结果?
什么变化使第5行产生结果?


line 1 is values of x
line 2 is actual f(x)
which mathematical function gives results of line 3 ?
What change gives results of line 4 ?
What change gives results of line 5 ?


这篇关于在这些条件下,我如何编写C程序以生成012345678910987654321的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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