(2014•青山湖区模拟)已知函数f(x)=cos
1个回答

由程序框图知:第一次运行f(1)=cos

π

3=

1

2,S=0+

1

2.n=1+1=2;

第二次运行f(2)=cos

3=-

1

2,S=

1

2,n=2+1=3,

第三次运行f(3)=cosπ=-1,S=

1

2,n=3+1=4,

第四次运行f(4)=cos

3=-

1

2,S=

1

2,n=4+1=5,

第五次运行f(5)=cos

3=

1

2,S=1,n=6,

第六次运行f(6)=cos2π=1,S=2,n=7,

直到n=2016时,程序运行终止,

∵函数y=cos

3是以6为周期的周期函数,2015=6×335+5,

又f(2016)=cos336π=cos(2π×138)=1,

∴若程序运行2016次时,输出S=2×336=672,

∴程序运行2015次时,输出S=336×2-1=671.

故选:C.