Created
April 3, 2017 17:34
-
-
Save daem-on/9c0ba69c676ca58a537b599ce89910b7 to your computer and use it in GitHub Desktop.
My first C program that does anything
This file contains 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> | |
void main() | |
{ | |
int range; | |
printf("Horizontal range: "); | |
scanf("%d",&range); | |
int vrange; | |
printf("Vertical range: "); | |
scanf("%d",&vrange); | |
int i; | |
for(i= -range;i<range;i++) { | |
printf("%03d ",i); | |
int d; | |
int val=i; //change 'i' to graph anything else | |
//floor val | |
if (val>vrange){ | |
val=vrange; | |
} | |
for(d=-vrange-1;d<val;d++) { | |
if (i == 0) { | |
printf("-"); | |
} else if(d == 0) { | |
printf("|"); | |
} else { | |
printf(" "); | |
} | |
} | |
if (d<-vrange) { | |
printf(" "); | |
} else if (d>=vrange) { | |
//basically do nothing | |
} else { | |
printf("x"); | |
} | |
for(d=d+1;d<vrange;d++) { | |
if (i == 0) { | |
printf("-"); | |
} else if(d == 0) { | |
printf("|"); | |
} else { | |
printf(" "); | |
} | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment