The console plots the sinusoidal and cosine curves simultaneously display

Source: Internet
Author: User

If you do not draw the sine/cosine curve in this article, you can look at this first: the console draws the sine/cosine curve

So, if you want to display it at the same time, we may need to draw 3 or 4 points in the same line. My thinking is relatively simple, but the algorithm looks very very untidy, but also hope to get everyone's help ...

I divide the entire graph into 4 layers, drawn from top to bottom, by the square root two and negative two of the square root of the y equals two points and the y-axis. Specific look at the code ...

#include <stdio.h>#include <math.h>intMain () {DoubleYintX,K1,K2; for(y=1; y>=-1; y-=0.1) {k1=ACOs(y) *Ten; K2=ASIN(y) *Ten;if(k1<k2&&k2>=0)        { for(x=1; x<k1;x++)printf(" ");printf("*"); for(x=k1+1; x<k2;x++)printf(" ");printf("*"); for(;x< --k2;x++)printf(" ");printf("*"); for(;x< +-k1;x++)printf(" ");printf("*\n"); }Else if(k2<k1&&1<=k2&&k2<= the)        { for(x=1; x<k2;x++)printf(" ");printf("*"); for(x=k2+1; x<k1;x++)printf(" ");printf("*"); for(;x< --k2;x++)printf(" ");printf("*"); for(x= --k2;x< +-k1;x++)printf(" ");printf("*\n"); }Else if(k1< ( --K2) && ( --K2) < ( +-K1) &&- the<=k2&&k2<=-1)        { for(x=1; x<k1;x++)printf(" ");printf("*"); for(;x< to-k2;x++)printf(" ");printf("*"); for(;x< +-k1;x++)printf(" ");printf("*"); for(;x< A+k2;x++)printf(" ");printf("*\n"); }Else if(( +-K1) < ( to-K2) &&- the<=k2&&k2<=-1)        { for(x=1; x<k1;x++)printf(" ");printf("*"); for(;x< +-k1;x++)printf(" ");printf("*"); for(;x< to-k2;x++)printf(" ");printf("*"); for(;x< A+k2;x++)printf(" ");printf("*\n"); }return 0;}

Do you have any better ideas welcome message AH ~

"This is the source code, do not need the resource points"

The console plots the sinusoidal and cosine curves simultaneously display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.