Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This program creates a basic graph using whole numbers. maxX sets the largest x value and has y adjust according to it. The function may be changed in the formula function. Possible improvments include allowing user to change function from input, allowing decimal numbers, and negative quadrants.
- */
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <iomanip>
- using namespace std;
- int digit(int number) {
- //This function gathers digits to set width of y numb line
- int count = 0;
- while(number != 0) {
- number = number / 10;
- count++;
- }
- return count;
- }
- int formula(int x){
- //this function serves to update maxY and f(x) using only one value
- return pow(x,2);
- }
- int main() {
- int maxX= 5;
- int maxY=formula(maxX);
- for(int y=0; y<=maxY; y++){
- cout << setw(digit(maxY)) << maxY-y;
- for(int x=0; x<=maxX; x++){
- if(formula(x)==(maxY-y)){
- cout << "o";
- }
- else
- cout << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement