雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C語言實(shí)現(xiàn)三角函數(shù)表

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊:

本文實(shí)例為大家分享了C語言列寫三角函數(shù)表的具體代碼,供大家參考,具體內(nèi)容如下

下面是用函數(shù)指針實(shí)現(xiàn)的三角函數(shù)表,其中cos函數(shù)、sin函數(shù)和tan函數(shù)都已經(jīng)在<math.h>中定義,函數(shù)tabulate中使用的函數(shù)ceil也屬于<math.h>,當(dāng)給定double型實(shí)參x時(shí),函數(shù)ceil會(huì)返回大于或等于x的最小整數(shù)。當(dāng)給定三角函數(shù)的起始值,終止值和步長以后,程序會(huì)打印出相對(duì)應(yīng)的三角函數(shù)值。

#include <math.h>
#include <stdio.h>

// 傳遞函數(shù)指針f時(shí),tabulate函數(shù)顯示函數(shù)f的值
void tabulate(double (*f)(double), double first, double last, double incr);

int main(void)
{
 double initial, final, increment;

 printf("Enter initial value: ");
 scanf("%lf", &initial);

 printf("Enter final value: ");
 scanf("%lf", &final);

 printf("Enter increment: ");
 scanf("%lf", &increment);

 printf("\n x cos(x)"
  "\n ------- -------\n");
 tabulate(cos, initial, final, increment);

 printf("\n x sin(x)"
  "\n ------- -------\n");
 tabulate(sin, initial, final, increment);

 printf("\n x tan(x)"
  "\n ------- -------\n");
 tabulate(tan, initial, final, increment);

 return 0;
}

void tabulate(double (*f)(double), double first, double last, double incr)
{
 double x;
 int i, num_intervals;

 num_intervals = ceil((last - first) / incr);
 for (i = 0; i <= num_intervals; i++) {
 x = first + i * incr;
 printf("%10.5f %10.5f\n", x, (*f)(x));
 }
}

參考資料:

《C語言程序設(shè)計(jì)現(xiàn)代方法》

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C++實(shí)現(xiàn)數(shù)據(jù)文件存儲(chǔ)與加載

欄    目:C語言

下一篇:C語言繪制三角函數(shù)曲線

本文標(biāo)題:C語言實(shí)現(xiàn)三角函數(shù)表

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/269.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有