Code c PART2
//Tinh sin X
//Tran van Thanh k55Cb n3
#include<stdio.h>
#include<conio.h>
#include<math.h>
double giaithua(double n)
{
if(n==0||n==1) return 1;
return n*giaithua(n-1);
}
int main()
{
double tg,x,a,n;
printf("Nhap goc can tinh (radian): ");
scanf("%lf",&a);
n=1;x=a;
do
{
tg=pow(a,2*n+1)/giaithua(2*n+1);
x+=pow(-1,n)*tg;
n++;
}
while(fabs(tg)>0.0001);
printf("Ket qua tinh theo CT: %10.8lf",x);
printf("
Ket qua tinh theo ham: %10.8lf",sin(a));
getch();
}
///cosX
#include<stdio.h>
#include<conio.h>
#include<math.h>
double giaithua(double n)
{
if(n==0||n==1) return 1;
return n*giaithua(n-1);
}
int main()
{
double tg,x,a,n;
printf("Nhap goc can tinh (radian): ");
scanf("%lf",&a);
n=1;x=1;
do
{
tg=pow(a,2*n)/giaithua(2*n);
x+=pow(-1,n)*tg;
n++;
}
while(fabs(tg)>0.0001);
printf("Ket qua tinh theo CT: %10.8lf",x);
printf("
Ket qua tinh theo ham: %10.8lf",cos(a));
getch();
}
//Cong ma tran.in ma tran..tinh do lech chuan
#include <stdio.h>
#include <conio.h>
//ham input array
void input_array(int A[],int n)
{
for(i=0;i<n;i++)
{
printf("A[%d] = ",i);
scanf("%d",&A[i]);
}
}
//ham display array
void display_array(int A[],int n)
{
for(i=0;i<n;i++)
{
printf("%4d",A[i]);
printf("\t");
}
}
//ham copy array
void copy_array(int A[],int B[],int n)
{
for(i=0;i<n;i++)
{
A[i]=B[i];
}
}
//ham tinh standard deviation
void standard_deviation(int A[], int n)
{
float trung_binh=0, tong=0;
double do_lech_chuan=0;
for(i=0; i<n; i++){
tong+=A[i];
}
trung_binh=tong/n;
tong=0;
for(i=0; i<n; i++){
tong+=((A[i] - trung_binh) * (A[i] - trung_binh));
}
trung_binh=tong/n;
do_lech_chuan=sqrt(trung_binh);
printf("
Do lech chuan la:");
printf("%-5lf", do_lech_chuan);
}
//ham main chinh
int main()
{
int A[30],B[30];
printf("Nhap so phan tu trong mang :
");
scanf("%d",&n);
printf("nhap cac phan tu trong mang :
");
input_array(B,n);
printf("Cac phan tu trong mang la :
");
display_array(B,n);
copy_array(A, B, n);
printf("
Mang dc copy la:
");
display_array(A, n);
standard_deviation(A, n);
getch();
}
//uCln
#include <stdio.h>
#include <conio.h>
int UCLN(int a, int b)
{
if (b==0)
return a;
return UCLN(b,a%b);
}
int main()
{
int a[10];
int n,i,k;
printf("nhap bao nhieu so :");
scanf("%d",&n);
for(i=0;i<=n-1;i++)
{
printf("cac so %d:",i+1);
scanf("%d",&a[i]);
if(i>0)
{
k=UCLN(a[0],a[i]);
a[0]=k;
}
}
printf("UCLN cua %d cac so la %d",n,a[0]);
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top