Lab Record Program No 8 Get link Facebook X Pinterest Email Other Apps December 10, 2022 8.Write a C Program to find Sin(x) and Cos(x) values using series expansion. A)PROGRAM FOR SUM OF SIN (X) SERIES /*x -x^3/3! + x^5/5! - .........*/ #include<stdio.h> #include<conio.h> #include<math.h> void main() { float x,s=0; int fact(int x); int n,i,t=1; clrscr(); printf("\nEnter the value of x & n "); scanf("%f%d",&x,&n); for(i=1; i<=n; i++) { s=s+pow(-1,(i+1))*(pow(x,t))/((float)fact(t)); printf("x^%d/%d!",t,t); if(i%2==0) printf("+"); else printf("-"); t=t+2; } printf("\nSum of series = %.2f",s); getch(); } int fact(int x) { int i,f=1; for(i=1; i<=x; i++) f=f*i; return(f); }B)PROGRAM FOR SUM OF COS (X) SERIES #include<stdio.h> #include<conio.h> void main() { int i, n; float x, sum=1, t=1; clrscr(); printf(" Enter the value for x : "); scanf("%f",&x); printf(" Enter the value for n : "); scanf("%d",&n); x=x*3.14159/180; /* Loop to calculate the value of Cosine */ for(i=1;i<=n;i++) { t=t*(-1)*x*x/(2*i*(2*i-1)); sum=sum+t; } printf(" The value of Cos(%f) is : %.4f", x, sum); getch(); } Get link Facebook X Pinterest Email Other Apps Comments
Program 27-40 February 23, 2023 PPS LAB RECORD PROGRAMS 1. Write a C program that converts a string representing a number in Roman numeral form to decimal form. [Follow regular convention for Roman numbers, Read string – parse it to convert in to decimal] Eg: Input: XL output: 40 Ans: Program: Program to convert Roman numeral to Decimal number. // Program to convert Roman Numerals to Numbers #include<stdio.h> #include<string.h> int value(char); intromanToDecimal(char[]); // Driver Program int main(void) { charstr[10]; intnum; printf("Enter Roman Number:"); scanf("%s",str); num=romanToDecimal(str); printf("Integer form of Roman Numeral is: %d",num); return 0; } // This function returns value of a Roman symbol int value(char r) { if (r == 'I') return 1; if (r == 'V') return 5; if (r == 'X') return 10; if (r == 'L') return 50; if (r == 'C') return 100; if (r... Read more
Comments
Post a Comment