如何编写程序只使用for循环来显示这些数量的集我很困惑? [英] how to write a program only using for loop to show these number of sets i am very confused ?

查看:63
本文介绍了如何编写程序只使用for循环来显示这些数量的集我很困惑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第1行 - 2 10 30 68 130

第2行 - 1 2 3 5 8 13 21 34 55

第3行 - 1 4 7 10 13 16 19 22 25



请用于循环,因为我老师给了一个任务:(





  #include    <   stdio.h  >  
#include < conio .h >
void main()
{
int a,b,c;
for (a = 1 ; a< = 25 ; a + = 3
{
printf( \ n\t3rd line:%d,a);
}
for (b = 2 ; b< = 55 ; b ++)
b + = 3 ;
c = b + 10;
{
printf( \ n\t\t\t:2nd :%d\\\
%d,b,C);
}

getch();



i刚刚写了这个,它正确地给出了第3行但是前两行怎么样他们就不那么简单。

解决方案

 #include< stdio.h> 
main()
{

int a = 1 ,b = 1 ,i,c;


printf( 第二行:);
for (i = 0 ; i< 9; i ++)
{
C = A;
a = b;
b = c + b;
printf( %d,a);
}
printf( \ n);

printf( 第1行:);
for (i = 1 ; i< 6; i ++)
{
printf( %d,(i * i * i)+ i);

}
printf( \ n);

printf( 第3行:);
for (a = 1 ; a< = 25 ; a + = 3
{
printf( %d,a);
}
printf( \ n);

}


您的老师将任务交给。至少要努力解决它。


要理解这些系列,有一个很好的技巧:形成第一个差异(即ba,cb,dc,ed ......)并观察。



如果你找不到规律性,那么重复这个过程,形成第二个差异,依此类推。



这将允许你找出公式或计算程序。



最后提示:从第三个开始。

1st line- 2 10 30 68 130
2nd line- 1 2 3 5 8 13 21 34 55
3rd line- 1 4 7 10 13 16 19 22 25

please only use for loop for this as my teacher gave a task :(


#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b,c;
    for(a=1;a<=25;a+=3)
    {	
        printf("\n\t3rd line:%d",a);
    }
    for(b=2;b<=55;b++)
    b+=3;
    c=b+10;
    {
        printf("\n\t\t\t:2nd:%d\n%d",b,c);
    }
    
getch();   


i just wrote this one , it gives 3rd line correctly but what about the 1st two lines they are''nt that simple.

解决方案

#include<stdio.h>
main()
{

    int a=1,b=1,i,c;


    printf("2nd line :");
    for(i=0;i<9;i++)
        {
        c=a;
        a=b;
        b=c+b;
        printf("%d ",a);
        }
    printf("\n");

        printf("1st line :");
    for(i=1;i<6;i++)
    {
        printf("%d ",(i*i*i)+i);

    }
    printf("\n");

    printf("3rd line :");
        for(a=1;a<=25;a+=3)
        {
             printf("%d ",a);
        }
        printf("\n");

}


Your teacher gave the task to you. At least make an effort to solve it.


To understand those series, there is one trick which works well: form the first differences (i.e. b-a, c-b, d-c, e-d...) and observe.

If you can''t find a regularity, then repeat the process, forming the second differences, and so on.

This will allow you to figure out a formula or a computational procedure.

Last hint: start with the third.


这篇关于如何编写程序只使用for循环来显示这些数量的集我很困惑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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