正在加载图片...
计 算 顺序结构程序示例 机 程 序·分别输入两个复数的实部与虚部,计算两个复数的 设 和、差、积、商并输出结果 计 基 #include <stdio. h 础 nt main0 实际需要输入4个实数 float a, b, c, d, real, imaginary printf("Inputreals and imaginaries of two complexesIn); scanf(%of, %of, %of, %op ,&a, &b, &c, &); printf("Sum: %f+%fin",a+c,b+d); printf( Difference: %f+ %ofin"a-c, b-d) real=a*c-b*d; imaginary =ad+b*ci printf("Product: %of+%ofin"real, imaginary); rel=(a“c+b“d)/(cc+d“; imaginary=(bc-a“d)/(cec+d printf("Quotient: %f+%fin",real, imaginary); return O: 清华大学计算中心 http://learn.tsinghua.edu.cn 5清华大学计算中心 http://learn.tsinghua.edu.cn 5 计 算 机 程 序 设 计 基 础 顺序结构程序示例 • 分别输入两个复数的实部与虚部,计算两个复数的 和、差、积、商并输出结果 #include <stdio.h> int main() { float a, b, c, d, real, imaginary; printf(“Input reals and imaginaries of two complexes\n”); scanf(“%f,%f,%f,%f”, &a, &b, &c, &d); printf(“Sum: %f + %fi\n”, a + c, b + d); printf(“Difference: %f + %fi\n”, a – c, b – d); real = a * c – b * d; imaginary = a * d + b * c; printf(“Product: %f + %fi\n”, real, imaginary); real = (a*c + b*d) / (c*c + d*d); imaginary = (b*c – a*d) / (c*c + d*d); printf(“Quotient: %f + %fi\n”, real, imaginary); return 0; } 实际需要输入4个实数
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有