Need assistance with C: Sorry about whitespace/formatting. code doesnt transcrib
ID: 663271 • Letter: N
Question
Need assistance with C:
Sorry about whitespace/formatting. code doesnt transcribe well into the text input with chegg...
Entering on a new line into a 2d array the points of a triangle. See my code vs. the output I am attempting.
I've tried it several ways and I just dont know what to do. I have two books that are useless with what I am trying to do. The while loop isn't needed but I want the incremented n value and the while loop was just a test to try it out. If you know a simpler way, please share.
My desired output:
Bold is user input.
If there is a different way to achieve this, any advice is welcome.
My code: for(x = 0; x < 3; x++){for(y = 0; y < 2; y++){
int n = 1;
while (n < 3){
printf("Enter point #%d as x and y: ", n);
scanf("%d", &points[x][y]);
++n;
}
}
}
Explanation / Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int points[3][2];
int x,y;
clrscr();
for(x = 0; x < 3; x++)
{
printf("Enter point # %d as x and y: ", x+1);
for(y = 0; y < 2; y++)
{
scanf("%d", &points[x][y]);
}
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.