本文介绍了如何使用正弦系列找到正弦值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想用正弦系列找到x的罪。 xx ^ 3/3!+ ...... i希望使用pow功能找到这个 添加了代码块 - OriginalGriff [/ edit] 我的尝试: #include < stdio.h > #include < math.h > int main() { int i,j,n,fact,ch,p; float x,sum,angle; 执行 { printf( \ n1。正弦系列\ n2。余弦系列\ n3。指数系列\ n4。退出\ n输入你的选择:); scanf( %d,& ch); switch (ch) { case 1 : printf( \ n输入x的值(以度为单位)和n在正弦系列中。\ n); scanf( %f,& x); printf( e); scanf( %d,& n); printf( \ n%d,n); angle = x; printf( hi); x = angle * 3 .14 / 180; fact = 1 ; sum = 0 ; p = 0 ; for (i = 1 ; i< = n; i + 2) { for (j = 2 ; j< = n; j ++) { fact = fact * j; } // printf(\ n%d,fact); sum + =(pow( - 1 ,p)*(( float )pow (X,I)/事实)); p ++; } printf( \ nsin(%。2f)=%。2f \ N,角度之和); break ; case 2 : printf( \ n输入x的值(以度为单位)和n在余弦系列中的值。\ n); scanf( %f%d,& x,& n); angle = x; x = x * 3 .14 / 180; fact = 1 ; sum = 0 ; for (i = 0 ,p = 0 ; i< = n; i + 2,p ++) { for (j = 1 ; j< = n; j ++) { fact * = j; } sum + =(pow( - 1 ,p)*(( float )POW(X,I)/事实)); } printf( \ ncos(%。2f)=%。2f \ N,角度之和); break ; case 3 : printf( \ n输入x的值(以度为单位)和n以指数级数表示。\ n); scanf( %f%d,& x,& n); angle = x; x = x * 3 .14 / 180; fact = 1 ; sum = 0 ; for (i = 0 ; i< n; i ++) { for (j = 1 ; j< = n; j ++) { fact * = j; } sum + =(( float )pow(x,i)/ fact); } printf( \\\e ^(%。2f)=%。2f \\ \,角度之和); break ; case 4 : exit( 0 ); break ; 默认:printf( \ n输入无效\\ n); } } while ( 1 ); return 0 ; } 解决方案 然后这样做,开始工作。 我们不做你的HomeWork。 HomeWork不会测试你乞求别人做你的工作的技巧,它会被设定为您可以考虑并帮助您的老师检查您对所学课程的理解,以及您在应用这些课程时遇到的问题。 你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。 所以,试一试,重读你的课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。 作为程序员,您的工作是创建算法解决特定问题,你不能依赖别人永远为你做,所以有一段时间你必须学会如何。而且越快越好。 当你要求解决方案时,就像试图通过培训其他人来学习开车一样。 创建算法基本上是找到数学并进行必要的调整以适应你的实际问题。 i want to find sin of x using sine series . x-x^3/3!+......i want to find this using pow function[edit]Code block added - OriginalGriff[/edit]What I have tried:#include<stdio.h>#include<math.h>int main(){ int i,j,n,fact,ch,p; float x,sum,angle; do { printf("\n1. Sine series\n2. Cosine series\n3. Exponential series\n4. Exit\nEnter your choice: "); scanf("%d",&ch); switch(ch){case 1: printf("\nEnter the value of x(in degree)and n in sine series.\n"); scanf("%f",&x); printf("e"); scanf("%d",&n); printf("\n%d",n); angle=x; printf("hi"); x=angle*3.14/180; fact=1; sum=0; p=0; for(i=1;i<=n;i+2) { for(j=2;j<=n;j++){ fact=fact*j;} //printf("\n%d",fact); sum+=(pow(-1,p)*((float)pow(x,i)/fact)); p++; } printf("\nsin(%.2f)=%.2f\n",angle,sum); break;case 2: printf("\nEnter the value of x(in degree)and n in cosine series .\n"); scanf("%f%d",&x,&n); angle=x; x=x*3.14/180; fact=1; sum=0; for(i=0,p=0;i<=n;i+2,p++) { for(j=1;j<=n;j++){ fact*=j;} sum+=(pow(-1,p)*((float)pow(x,i)/fact)); } printf("\ncos(%.2f)=%.2f\n",angle,sum); break;case 3: printf("\nEnter the value of x(in degree)and n in exponential series.\n"); scanf("%f%d",&x,&n); angle=x; x=x*3.14/180; fact=1; sum=0; for(i=0;i<n;i++) { for(j=1;j<=n;j++){ fact*=j;} sum+=((float)pow(x,i)/fact); } printf("\ne^(%.2f)=%.2f\n",angle,sum); break;case 4: exit(0);break; default:printf("\n Invalid input\n");} }while(1); return 0;} 解决方案Then do it, start working.We do not do your HomeWork.HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.Any failure of you will help your teacher spot your weaknesses and set remedial actions.So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.is wrong, the last statement in the for clause ha no effect, it should be i+=2. Moreover, the fact variable must be initialized immediately before the factorial loop (by the way, it is better using a float variable for holding the factorial result, because it becomes large soon).You might fix your code this way:#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ int i,j,n,ch,p; float fact; float x,sum,angle; do { printf("\n1. Sine series\n2. Cosine series\n3. Exponential series\n4. Exit\nEnter your choice: "); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter the value of x(in degree)and n in sine series.\n"); scanf("%f",&x); scanf("%d",&n); angle = x; x=x*M_PI/180; sum=0.0; p=0; for(i=1;i<=n;i+=2) { fact=1; for(j=2;j<=i;j++) { fact=fact*j; } sum+=(pow(-1,p)*((float)pow(x,i)/fact)); p++; } printf("\nsin(%.2f)=%.2f\n",angle,sum); break; //...However I would factor out the sin computation in a function, and I would also compute the terms incrementally, e.g.#include <stdio.h>#include <math.h>double comp_sin( double x, int n){ double sign = 1.0; double fact = 1.0; double sum=0.0; double x2 = x * x; int k; for (k=0; k<n; ++k) { sum += (sign * x) / fact; // update the factors sign = sign > 0.0 ? -1.0 : 1.0; // toggle the sign fact *= (2.0 * k + 2.0) * (2.0 * k + 3.0); // compute the next 'factorial' factor x *= x2; // compute the next 'power' factor } return sum;}int main(){ int n; double angle; printf("please enter the angle in degres and the number of terms of the series\n"); scanf("%lf", &angle); scanf("%d", &n); printf("sin(%g) = %g\n", angle, comp_sin(angle*M_PI/180, n )); return 0;} 这篇关于如何使用正弦系列找到正弦值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 03:10