You are on page 1of 7

1. Vit chng trnh tnh tng S= 1! + 2! + 3! +.+n!

#include<stdio.h>
#include<conio.h>
main()
{
int n,i=0;
double s=0,a=1;
clrscr();
printf("Nhap n: ");
scanf("%d",&n);
while (i<n)
{
++i;
a=a*i;
s=s+a;
}
printf("Tong S:= %0.1lf",s);
getch();
}

2. Vit chng trnh tnh tng S=


#include<stdio.h>
#include<conio.h>
main()
{
int n,i=0,j;
double s=0,s1,a=1,b;
printf("Nhap n: ");
scanf("%d",&n);
while (i<n)
{
++i;
a=a*i;
b=1;
s1=0;
j=0;
while(j<i)
{
++j;
b=b*j;
s1=s1+b;
}
s=s+(a/s1);
}
printf("Tong S:= %0.3lf",s);
getch();
}

1!
2!
3!
n!
+
+
+ +
1 ! 1!+ 2! 1!+ 2! +3 !
1 !+ 2!+ 3! ++n !

3. Tnh tng S =

12+ 22+3 2+ +n2

#include<stdio.h>
#include<conio.h>
main()
{
int n,i=0,j;
double s=0,s1,a=1,b;
printf("Nhap n: ");
scanf("%d",&n);
while (i<n)
{
++i;
a=a*i;
b=1;
s1=0;
j=0;
while(j<i)
{
++j;
b=b*j;
s1=s1+b;
}
s=s+(a/s1);
}
printf("Tong S:= %0.3lf",s);
getch();
}

4. Vit chng trnh tnh tin in vi iu kin sau


iu kin s Kwh
Kwh 50 Kwh
50 < Kwh 100 Kwh
Kwh>100
#include<stdio.h>
#include<conio.h>
main()
{
double tien,kwh;
clrscr();
printf("Nhap so Kwh cua ban: ");
scanf("%lf",&kwh);
if (kwh>100)
tien=150000+(kwh-100)*3000;
else if(kwh>50)
tien=50000+(kwh-50)*2000;
else if(kwh>0)
tien=kwh*1000;
else tien=0;
printf("Tien dien cua ban la: %0.lf VND",tien);
getch();
}

H s tin
1000 VND/Kwh
2000 VND/Kwh
3000 VND/Kwh

4. Vit chng trnh tnh tin thu vi iu kin sau:


Khung Lng (Triu)
0->9
9->14
14->19
19->24
24->29
29<
#include<stdio.h>
#include<conio.h>

Tin Thu ng
Thu = 0%
Thu = 5%
Thu = 10%
Thu = 15%
Thu = 20%
Thu = 25%

main()
{
double luong,thue;
clrscr();
printf("Nhap tien luong cua ban: ");
scanf("%lf",&luong);
if (luong>29000000)
thue=2500000+(luong-29000000)*0.25;
else if(luong>24000000)
thue=1500000+(luong-24000000)*0.2;
else if(luong>19000000)
thue=750000+(luong-19000000)*0.15;
else if(luong>14000000)
thue=250000+(luong-14000000)*0.1;
else if(luong>9000000)
thue=(luong-9000000)*0.05;
else thue=0;
printf("Tien thue thu nhap ca nhan cua ban la: %0.0lf VND",thue);
getch();
}

5. Gii h phng trnh bng php lp Gauss

#include<conio.h>
#include<stdio.h>
main()
{
int i,n;
float x,y,z,x0,y0,z0;
clrscr();
printf("Nhap x0= ");
scanf("%f",&x0);
printf("Nhap y0= ");
scanf("%f",&y0);
printf("Nhap z0= ");
scanf("%f",&z0);
printf("Nhap so lan lap: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
x=(5+y0+z0)/8;
y=(5+x0+2*z0)/10;
z=(7+x0+2*y0)/5;
x0=x;
y0=y;
z0=z;
}
printf("\nBo nghiem cua he la:\nX= %0.4f\nY= %0.4f\nZ= %0.4f",x,y,z);
getch();
}

6. Vit chng trnh tinh mch in

#include<stdio.h>
#include<conio.h>
main()
{
double R1,X1,P1,Q1,U1,R2,X2,P2,Q2,U2,UN,PN,QN,TAM1,TAM2;
printf("Nhap R1,X1,P1,Q1 nhap xong moi gia tri nhan enter!\n");
scanf("%lf%lf%lf%lf%lf",&R1,&X1,&P1,&Q1);
printf("Nhap R2,X2,P2,Q2,U2 nhap xong moi gia tri nhan enter\n");
scanf("%lf%lf%lf%lf%lf",&R2,&X2,&P2,&Q2,&U2);
U1=U2+(P2*R2+Q2*X2)/U2;
UN= U1+(((P2*P2+Q2*Q2)*(R1*R2+X1*X2)+(P1+P2)*R1+
(Q1+Q2)*X2)/U1);
TAM1=((P2*P2+Q2*Q2)*R2+P1+P2)*((P2*P2+Q2*Q2)*R2+P1+P2);
TAM2=((P2*P2+Q2*Q2)*X2+Q1+Q2)*((P2*P2+Q2*Q2)*X2+Q1+Q2);
PN=(((TAM1+TAM2)*R1)/(U1*U1))+P1+(((P2*P2+Q2*Q2)*R2)/(U2*U2))+P2;
QN=(((TAM1+TAM2)*X1)/(U1*U1))+Q1+(((P2*P2+Q2*Q2)*X2)/(U2*U2))+Q2;
printf("UN= %0.2lf\nPN= %0.2lf\nQN= %0.2lf\n",UN,PN,QN);
getch();
}

You might also like