C语言题目~~
发布网友
发布时间:2022-04-30 17:44
我来回答
共4个回答
热心网友
时间:2022-06-28 15:25
#include<stdio.h>
#include<math.h>
typedef struct fushu
{
float real;
float fail;
}ob;
void normalize(ob a)
{
double save=sqrt(a.real*a.real+a.fail*a.fail);
printf("归一化后的复数为:\n");
printf("%f+%fi\n",a.real/save,a.fail/save);
}
void main()
{
ob a;
printf("请输入一个复数(a+bi):\n");
printf("a=");
scanf("%f",&a.real);
printf("b=");
scanf("%f",&a.fail);
normalize(a);
}
热心网友
时间:2022-06-28 15:25
/*****************************
我这个程序按照你的要求使用了结构体指针类型作为函数参数
*/
#include <stdio.h>
#include <math.h>
/*实数结构体*/
struct comp
{
double a; /*实部*/
double b; /*虚部*/
};
void Normalize(struct comp *p)
{
double c,d;
c=p->a/sqrt(p->a*p->a+p->b*p->b);
d=p->b/sqrt(p->a*p->a+p->b*p->b);
p->a=c;
p->b=d;
}
int main()
{
struct comp c,*p=&c;
c.a=9.3;
c.b=3.0;
Normalize(p);
printf("归一化结果为%lf + %lf i\n",c.a,c.b);
return 0;
}
热心网友
时间:2022-06-28 15:26
#include<stdio.h>
#include<math.h>
#include<string.h>
struct F
{
double a;
double b;
};
void PNT( F * s , F * g )
{
g->a = s->a*sqrt(s->a*s->a + s->b*s->b);
g->b = s->b*sqrt(s->a*s->a + s->b*s->b);
}
int main()
{
F e;
F g;
printf("a=? b = ? \n");
scanf("%lf%lf",&e.a,&e.b);
PNT(&e,&g);
printf("归一化结果为:\n");
printf("%lf + %lf i\n",g.a,g.b);
getchar();
getchar();
return 0;
}
热心网友
时间:2022-06-28 15:26
#include <math.h>
#include <stdio.h>
typedef struct
{
double real;
double img;
}Complex;
Complex Normalize(Complex a)
{
double x=a.img*a.img+a.real*a.real;
x=sqrt(x);
a.img /=x;
a.real /=x;
return a;
}
int main()
{
double y;
Complex x;
x.img=3;
x.real =4;
x=Normalize(x);
y=x.img*x.img+x.real*x.real;//y为1 用于验证
printf("x.real=%lf\nx.real=%lf\ny=%lf\n",x.real ,x.img ,y);
return 0;
}