Issue
This may be really dumb but I have been unable to print a fraction to my terminal. How do I make my fraction look like this and not(2/3).
I've tried the code below but I don't know how I'll print multiple fractions on the same line.
printf("2\n");
printf("-\n");
printf("3\n");
Solution
Ugly, but if the example of one fraction on 3 lines, as you have shown in your post is okay, then this illustrates multiple fractions on the same 3 lines. Note the use of width specifier in format strings:
int main(int argc, char *argv[])
{
const char array[3][5] = {{'1','2','3','4','5' },
{'-','-','-','-','-'},
{'2','3','4','5','6' }};
for(int i=0;i<3;i++)
{
for(int j=0;j<5;j++)
{
printf("%6c", array[i][j]);
// | width specifier, change value as needed for formatting.
}
printf("\n");
}
return 0;
}
For a prettier output, you could always use unicode characters, but then you would need to use wchar, and still be limited to seeing Vulgar fraction form: 1/2
.
Answered By - ryyker Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.