Skip to content

Instantly share code, notes, and snippets.

@lazyval
Created February 21, 2012 21:20
Show Gist options
  • Save lazyval/1879024 to your computer and use it in GitHub Desktop.
Save lazyval/1879024 to your computer and use it in GitHub Desktop.
unholy c++
#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