关于c的编程练习题问题

时间:2021-11-16 12:16:11
    本人初入csdn,也是个计算机系的初学者,自己找来了一些编程练习题来做遇到一些问题,希望有大佬可以帮帮我。
    题目是在不使用数组的前提下用“*”在屏幕上打印出正弦函数图像。下面是我做的:
#include<stdio.h>
#include<math.h>
int main()
{
double y;
int x,m;
for(y=1;y>=0;y-=0.1)
{
m=asin(y)*10;
for(x=0;x<m;x++)
printf(" ");
printf("*");
for(;x<30-m;x++)
printf(" ");
printf("*\n");
}
for(y=0;y>=-1;y-=0.1)
{
m=asin(y)*10;
for(x=0;x<m+60;x++)
printf(" ");
printf("*");
for(x=0;x<30-m;x++)
printf(" ");
printf("*\n");
}
return 0;

下面是运行截图:
关于c的编程练习题问题
改了很久找不到错误原因,希望可以在这里虚心接受大佬们的指导。
万分感谢

6 个解决方案

#1


[int _tmain(int argc, _TCHAR* argv[])
{
double y;
int x,m;
for(y=1;y>=0;y-=0.1)
{
m=asin(y)*10;
for(x=0;x<m;x++)
printf(" ");
printf("*");
for(;x<30-m;x++)
printf(" ");
printf("*\n");
}
for(y=0;y>=-1;y-=0.1)
{
m=asin(y)*10;
m=abs(m);
for(x=0;x<32+m;x++)
printf(" ");
printf("*");
for(;x<62-m;x++)
printf(" ");
printf("*\n");
}
system("PAUSE");
return 0;
},
该回复于2018-02-02 23:03:55被管理员删除
, for(y=0;y>=-1;y-=0.1)
{
m=asin(y)*10;
for(x=0;x<m+60;x++)
printf("`");
printf("*1");
for(x=0;x<30-m;x++)
printf("`");
printf("*2\n");

把你第二个for改成这样,也许你会明白错在哪了 关于c的编程练习题问题, 关于c的编程练习题问题
尴尬,点错图,     哇好厉害好厉害,我一下子就看懂了,谢谢谢谢,果然还是csdn里面牛人多呀,真的谢谢。,
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI       3.14159265358979323846
#endif
#define W 80
#define H 20
char s[W][H];
double x,y;
int i,j,i1;
void main() {
    for (j=0;j<H;j++)
        for (i=0;i<W;i++)
            s[i][j]=' ';
    i1=0;
    for (x=0.0;x<=359.0;x+=1.0) {
        i=(int)(x*W/360.0);
        if (i<0) i=0;
        if (i>W-1) i=W-1;
        y=sin(x*M_PI/180.0);
        j=(int)(H/2-(H/2-1)*y);
        if (j<0) j=0;
        if (j>H-1) j=H-1;
        if (i1!=i) {
            s[i][j]='*';
            i1=i;
        }
    }
    printf("sin\n");
    for (j=0;j<H;j++) {
        for (i=0;i<W;i++) {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }
    for (j=0;j<H;j++)
        for (i=0;i<W;i++)
            s[i][j]=' ';
    i1=0;
    for (x=0.0;x<=359.0;x+=1.0) {
        i=(int)(x*W/360.0);
        if (i<0) i=0;
        if (i>W-1) i=W-1;
        y=cos(x*M_PI/180.0);
        j=(int)(H/2-(H/2-1)*y);
        if (j<0) j=0;
        if (j>H-1) j=H-1;
        if (i1!=i) {
            s[i][j]='*';
            i1=i;
        }
    }
    printf("cos\n");
    for (j=0;j<H;j++) {
        for (i=0;i<W;i++) {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }
}
//sin
//
//              *************
//            **             **
//          **                 **
//        **                     **
//      **                         **
//     *                             *
//   **                               **
//  *                                   *
// *                                     **
//                                         *                                     *
//                                          *                                   *
//                                           **                               **
//                                             *                             *
//                                              **                         **
//                                                **                     **
//                                                  **                 **
//                                                    **             **
//                                                      ****** ******
//                                                            *
//cos
//
// ******                                                                   ******
//       **                                                               **
//         **                                                           **
//           **                                                       **
//             **                                                   **
//               *                                                 *
//                **                                             **
//                  *                                           *
//                   *                                         *
//                    **                                     **
//                      *                                   *
//                       **                               **
//                         *                             *
//                          **                         **
//                            **                     **
//                              **                 **
//                                **             **
//                                  ****** ******
//                                        *
]

#1


[int _tmain(int argc, _TCHAR* argv[])
{
double y;
int x,m;
for(y=1;y>=0;y-=0.1)
{
m=asin(y)*10;
for(x=0;x<m;x++)
printf(" ");
printf("*");
for(;x<30-m;x++)
printf(" ");
printf("*\n");
}
for(y=0;y>=-1;y-=0.1)
{
m=asin(y)*10;
m=abs(m);
for(x=0;x<32+m;x++)
printf(" ");
printf("*");
for(;x<62-m;x++)
printf(" ");
printf("*\n");
}
system("PAUSE");
return 0;
},
该回复于2018-02-02 23:03:55被管理员删除
, for(y=0;y>=-1;y-=0.1)
{
m=asin(y)*10;
for(x=0;x<m+60;x++)
printf("`");
printf("*1");
for(x=0;x<30-m;x++)
printf("`");
printf("*2\n");

把你第二个for改成这样,也许你会明白错在哪了 关于c的编程练习题问题, 关于c的编程练习题问题
尴尬,点错图,     哇好厉害好厉害,我一下子就看懂了,谢谢谢谢,果然还是csdn里面牛人多呀,真的谢谢。,
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI       3.14159265358979323846
#endif
#define W 80
#define H 20
char s[W][H];
double x,y;
int i,j,i1;
void main() {
    for (j=0;j<H;j++)
        for (i=0;i<W;i++)
            s[i][j]=' ';
    i1=0;
    for (x=0.0;x<=359.0;x+=1.0) {
        i=(int)(x*W/360.0);
        if (i<0) i=0;
        if (i>W-1) i=W-1;
        y=sin(x*M_PI/180.0);
        j=(int)(H/2-(H/2-1)*y);
        if (j<0) j=0;
        if (j>H-1) j=H-1;
        if (i1!=i) {
            s[i][j]='*';
            i1=i;
        }
    }
    printf("sin\n");
    for (j=0;j<H;j++) {
        for (i=0;i<W;i++) {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }
    for (j=0;j<H;j++)
        for (i=0;i<W;i++)
            s[i][j]=' ';
    i1=0;
    for (x=0.0;x<=359.0;x+=1.0) {
        i=(int)(x*W/360.0);
        if (i<0) i=0;
        if (i>W-1) i=W-1;
        y=cos(x*M_PI/180.0);
        j=(int)(H/2-(H/2-1)*y);
        if (j<0) j=0;
        if (j>H-1) j=H-1;
        if (i1!=i) {
            s[i][j]='*';
            i1=i;
        }
    }
    printf("cos\n");
    for (j=0;j<H;j++) {
        for (i=0;i<W;i++) {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }
}
//sin
//
//              *************
//            **             **
//          **                 **
//        **                     **
//      **                         **
//     *                             *
//   **                               **
//  *                                   *
// *                                     **
//                                         *                                     *
//                                          *                                   *
//                                           **                               **
//                                             *                             *
//                                              **                         **
//                                                **                     **
//                                                  **                 **
//                                                    **             **
//                                                      ****** ******
//                                                            *
//cos
//
// ******                                                                   ******
//       **                                                               **
//         **                                                           **
//           **                                                       **
//             **                                                   **
//               *                                                 *
//                **                                             **
//                  *                                           *
//                   *                                         *
//                    **                                     **
//                      *                                   *
//                       **                               **
//                         *                             *
//                          **                         **
//                            **                     **
//                              **                 **
//                                **             **
//                                  ****** ******
//                                        *
]