C代码和运行结果如下:
符合样例输出,望采纳~
附源码:
#include <stdio.h>
#include <string.h>
int main() {
char s[100]
int n
while (1) {
scanf("%s", s)
if (strcmp(s, "#") == 0) // 读入"#"结束
break
n = strlen(s)
if (s[n - 1] == 's' || s[n - 1] == 'x' || s[n - 1] == 'o' ||
n >1 &&s[n - 2] == 'c' &&s[n - 1] == 'h' ||
n >1 &&s[n - 2] == 's' &&s[n - 1] == 'h') {
printf("%ses\n", s)
}
else if (s[n - 1] == 'y') {
s[n - 1] = 'i'
printf("%ses\n", s)
}
else
printf("%ss\n", s)
}
return 0
}
在数学中一个复数可以定义为 (z=a + bi) 的形式。 C 语言在 ISO C99 时就引入了复数类型。它是通过 complex.h 中定义的。 我们可以使用 complex , __complex__ , 或 _ComplexI 类型符号来表示。
在C语言中有三种复数类型,分别为 float complex , double complex , long double complex 。他们之间 的区别就是表示复数中实部和虚步的数的数据类型不同。 complex 其实就是一个数组,数组中有两个元素,一个表示复数的实部,一个表示复数的虚部。
源代码如下:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double sum(double* x)
void main()
{
double *a,s=0.0
a=(double*)malloc(sizeof(double))
*a=5
s=sum(a)
printf("求和的结果是: %lf\n",s)
}double sum(double* x)
{
int j=0
double s=0.0
for(j=0j<=3j++)
{
s=s+pow(*x,j)
}
s=s*2
return s
}
扩展资料
输入任意两个复数差与商的源代码如下
typedef struct{
float r
float im
Complex
Complex res
Complex* add(Complex* a, Complex* b) {
res.r = a->r + b->r
res.im = a->im + b->im
return &res
}
Complex* div(Complex* a, Complex* b) {
float d = (b->r*b->r + b->im*b->im)
res.r = (a->r*b->r + a->im*b->im)/d
res.im = (a->im*b->r - a->r*b->im)/d
return &res
#include <stdio.h>typedef struct {
float r
float i
}Complex
Complex readComlexNumber() {
Complex n
printf("Input real part:")
scanf("%f", &n.r)
printf("Input imaginary part:")
scanf("%f", &n.i)
return n
}
Complex sumComplex(Complex a, Complex b) {
Complex c
c.r = a.r + b.r
c.i = a.i + b.i
return c
}
Complex differeneComplex(Complex a, Complex b) {
Complex c
c.r = a.r-b.r
c.i = a.i-b.i
return c
}
Complex multiplyComplex(Complex a, Complex b) {
Complex c
c.i = a.r * b.i + a.i*b.r
c.r = a.r * b.r - a.i*b.i
return c
}
Complex divideComplex(Complex a, Complex b) {
Complex c
c.r = (a.r*b.r+a.i*b.i)/(b.r*b.r+b.i*b.i)
c.i = (a.i*b.r-a.r*b.i)/(b.r*b.r+b.i*b.i)
return c
}
void printComplex(Complex n) {
printf("%.2f+%.2fi", n.r, n.i)
}
int main(){
Complex a, b, c
printf("Input Complex number a:\n")
a = readComlexNumber()
printf("Input Complex number b:\n")
b = readComlexNumber()
printf("The 2 Complex a & b is :\n")
printComplex(a) printf(" and ") printComplex(b)
//sum
c = sumComplex(a, b)
printf("\n (a+b)=") printComplex(c)
//diff
c = differeneComplex(a, b)
printf("\n (a-b)=") printComplex(c)
//multiply
c = multiplyComplex(a, b)
printf("\n (a*b)=") printComplex(c)
//divide
c = divideComplex(a, b)
printf("\n (a/b)=") printComplex(c)
return 0
}