⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hw4.c

📁 Computes the length of a line using two (x,y) points. Uses pointers
💻 C
字号:
/*************************************************************needed files, Lines.c and Lines.h. This is able to	**take in 4 values and set them to points using pointers then 	**uses a memory allocation to print them off in the reverse	**order they were entered while you claculate the distance	**between the points						*****************************************************************/	#include "Lines.h"	//You call it like this becasue it contains function prototypes.#include <stdio.h>#include<stdlib.h>void printLineSegment(struct line*, int);	int main(int argc, char* argv[]){		int size = atoi(argv[1]);	//transfoirms the input from a string to an integer	struct line * line_arr;			line_arr = (struct line*)malloc(size+1);	//set up an allocated memory spot to perform all of the tasks at hand and store the values to be input 	int i;	for(i = 0; i<size; i++)		//given the argument input decrememnt the size until it = 0	{		printf("Enter x1 y1 x2 y2:\n");		scanf("%lf %lf %lf %lf",&line_arr[i].p1.x,&line_arr[i].p1.y,&line_arr[i].p2.x,&line_arr[i].p2.y);	//scan in the numbers as long floating points								// then store them in in memory adresses that are allocated my the line array	}	printLineSegment(line_arr, size);	//go to printLineSegment using the size of the array	return 0;}void printLineSegment(struct line* lines,int size){	int i;	double dist = 0;	//just initialize the distance to be 0		for(i = (size-1); i>=0 ; i--)	//make sure you start printing the line at value 1 - the argument to ensure they all are admitted	{				dist = length_line(&lines[i]);	//call the distance from the Lines.c code		printf("Line: %.2f,%.2f %.2f,%.2f dist: %.2f\n", lines[i].p1.x, lines[i].p1.y, lines[i].p2.x, lines[i].p2.y, dist);		//print off the values as inputs that are seperated by a space and do not read in leading 0's and what not.		//That was taken care of in the scan function becasue they were stored approrpiatly.		//This for loop is going to print off the lines in the reverse order that they were entered.			}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -