简单编程题

版权声明:如果能帮上忙最好啦,转载注明出处谢谢啦♪(・ω・)ノ https://blog.csdn.net/Rainbow__sea/article/details/78604177

使用函数求两个复数的积

#include <stdio.h>

double result_real,result_imag;

void complex_prod(double real1,double imag1,double real2,double imag2);

int main(void)

{

    double imag1,imag2,real1,real2;

 

    printf("Enter 1st complex number(real and imaginary):");

    scanf("%lf%lf",&real1,&imag1);

    printf("Enter 2nd complex number(real and imaginary):");

    scanf("%lf%lf",&real2,&imag2);

    complex_prod(real1,imag1,real2,imag2);

    printf("product of complex is %f+%fi\n",result_real,result_imag);

 

    return 0;

}

void complex_prod(double x1,double y1,double x2,double y2)

{

    result_real=x1*x2-y1*y2;

    result_imag=x1*y2+x2*y1;

}



求矩形各行元素之和:输入两个正整数mnm>=1,n<=6),然后输入该mn列二位数组a中的元素,分别求出各行元素之和并输出。

#include <stdio.h>

int main()

{

    int a[6][6],i,j,m,n,sum;

 

    printf("Input m,n:");

    scanf("%d%d",&m,&n);

    printf("Input array:\n");

    for(i=0;i<m;i++)

        for(j=0;j<n;j++)

            scanf("%d",&a[i][j]);

            sum=0;

    for(i=0;i<m;i++){

            sum=0;

        for(j=0;j<n;j++)

            sum=sum+a[i][j];

        printf("sum of row %d is %d\n",i,sum);

    }

 

    return 0;

}



阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页