// WAP to print a vertically aligned sinusoidal curve #include #include #include const float PI = 3.14159; const float LAST = 2 * PI; const int STEPS = 4; float point(float A, float rad) { return A * sin(rad); } int getSpaces(float A, float y) { int spaces = round(y * 2) * A * 2; if (abs(y) == 1) { spaces += y * A; } return spaces; } int main() { float A; printf("Enter amplitude: "); scanf("%f", &A); int base_spaces = getSpaces(A, PI / 2); int cycles; printf("Enter the no. of cycles: "); scanf("%d", &cycles); float y; int spaces; for (int i = 0; i < cycles; i++) { for (float rad = 0; rad < LAST; rad += LAST / (POINTS_PER_CYCLE * A)) { if (rad == 0 && i > 0) { continue; } y = point(A, rad); spaces = base_spaces + getSpaces(A, y); for (int j = 0; j < spaces; j++) { printf(" "); } printf("* %g, %d\n", y, spaces); } } return 0; }