以下程序段()的功能是计算序列1+1/2+1/3+...的前N项之和。
A. inti,n,sum;scanf("%d",&n);sum=0;for(i=1;i<=n;i++){sum=sum+1.0/i;}
B. inti,n;doublesum;scanf("%d",&n);for(i=1;i<=n;i++){sum=sum+1.0/i;}
C. inti,n;doublesum;scanf("%d",&n);sum=0;for(i=1;i<=n;i++){sum=sum+1.0/i;}
D. inti,n;doublesum;scanf("%d",&n);sum=0;for(i=1;i<=n;i++){sum=sum+1/i;}
查看答案
以下程序段( )的功能是计算n的阶乘,假设计算结果不超过双精度范围。
A. int i, n;double product;scanf("%d", &n);product = 0;for (i = 1; i <= n; i++){ product = product * i;}
B. int i, n, product;scanf("%d", &n);product = 1;for (i = 1; i <= n; i++){ product = product * i;}
C. int i, n;double product;scanf("%d", &n);for (i = 1; i <= n; i++){ product = product * i;}
D. int i, n;double product;scanf("%d", &n);product = 1;for (i = 1; i <= n; i++){ product = product * i;}
下列程序段的输出结果是_______。int a=1,b=2,c=3;if(c=a)printf(“%d\n”,c);else printf(“%d\n”,b);
下面程序用于判断a,b,c能否构成三角形,若能,输出YES,否则输出NO。当给a、b、c输入三角形三条边长时,确定a、b、c、能构成三角形的条件是需同时满足三个条件:a+b>c,a+c>b,b+c>a。请填空。#include int main( ){ float a,b,c; scanf("%f%f%f",&a,&b,&c); if(_____)printf("YES\n");/*a、b、c能构成三角形*/ else printf("N0\n");/*a、b、c不能构成三角形*/ return 0;}
以下程序段的输出结果是________。#include int main( ){ int x=1,y=0,a=0,b=0; switch(x) {case 1:switch(y){case 0:a++;break;case 1:b++;break;} } printf("%d,%d\n",a,b); return 0;}