|
|
вернуться в форумcorrect soulotion #include<stdio.h> #include "stdafx.h" #include<conio.h> #include<math.h> #include<iostream> double a[131072]; int main(){ int count=0; int i=0; while(std::cin>>a[i]) { a[i]=sqrt(a[i]); count++;i++;} for(int i=count-1;i>=0;i--) printf("\n%.4lf",a[i]); getch(); return 0; } it's a correct code about this program Re: correct soulotion Excuse me. Your code seems broken. 1) not working because of included headers. 2) Headers' names written in C style and C++ header 3) Using two counters. WHY, MAN, WHY. 4) Using realization-dependent headers(conio) I present more correct one, C++. #include <iostream> //for cin #include <cmath> //for sqrt #include <cstdio> //for printf, replace with <iostream> if you need true cpp // No unneeded headers. using namespace std; double nums[140000]; int main() { int x; for(x = 0; cin >> nums[x];x++) {; //Loop does everything for us. x isn't declared here because we need it outside. }; //You can clearly see that only one counter is needed. x--; for(;x > -1; x--) { printf("%.4lf\n", sqrt(nums[x])); //Could use cout. How-to: //cout.precision(4); //cout << std::fixed; //Put them in the main(), not here. }; }; //Ted E. Bear saves the day. EOF. |
|
|