C
임시파일
by KWONE
2024. 7. 30.
#include <stdio.h>
#include <math.h>
typedef struct studentTag {
char name[10];
int age;
double gpa;
}student;
typedef struct point {
int xpos;
int ypos;
}Point;
double get_distance(Point *p1, Point *p2)
{
return sqrt((pow(((p1->xpos) - (p2->xpos)), 2) + pow(((p1->ypos) - (p2->ypos)), 2)));
}
int main()
{
student a = { "kim",20,4.3 };
student b = { "park",21,4.2 };
Point p1 = { 1,2 };
Point p2 = { 9,8 };
printf("%.2lf",get_distance(&p1, &p2));
return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
int two[10];
for (int i = 0; i < 10; i++) {
two[i] = pow(2, i);
}
for (int i = 0; i < 10; i++) {
printf("%d\n", two[i]);
}
return 0;
}
#include <stdio.h>
typedef struct complex {
float real;
float imaginary;
}Complex;
Complex complex_add(Complex a, Complex b) {
Complex result;
result.real = (a.real) + (b.real);
result.imaginary = (a.imaginary) + (b.imaginary);
return result;
}
int main() {
Complex num1 = { 1.0, 2.0 };
Complex num2 = { 3.0, 4.0 };
Complex sum = complex_add(num1, num2);
printf("Sum: %.1f + %.1fi\n", sum.real, sum.imaginary);
return 0;
}