Created
February 21, 2012 21:20
-
-
Save lazyval/1879024 to your computer and use it in GitHub Desktop.
unholy c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
int main() { | |
while(true) { | |
float x = 0.01, z, p = 1; | |
int c, n = 10, i = 1; | |
printf("\nInsert computation type: "); | |
scanf("%d", &c); | |
switch (c) { | |
case 1: | |
while (i <= n) { | |
i++; | |
p *= tan(fabs(x)) * (sqrt(i)); | |
} | |
break; | |
case 2: | |
// Мы уже определили переменную-счетчик i -- нет нужды делать это снова | |
for (; i <= n; i++) { | |
p *= tan(fabs(x)) * (sqrt(i)); | |
} | |
break; | |
case 3: | |
do { | |
i++; | |
p *= tan(fabs(x)) * (sqrt(i)); | |
} while (i < n); | |
break; | |
default: | |
// Если пользователь ввел значение отличное от 1,2,3 | |
printf("Error. Unknown computation type."); | |
return (1); | |
} | |
z = (cos(x) * cos(x)) + cos(p); | |
printf("\n z=%.3f", z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment