bai tap lap trinh
Bai 20
#include <iostream>
using namespace std;
void main()
{
int a,b,c,d;
cout<<"tong so giay :
";
cin>>a;
b=a/3600;
c=a-b;
d=c/60;
cout<<"gio : "<<b<<"
";
cout<<"phut : "<<d<<"
";
cout<<"giay : "<<c%60<<"
";
}
bai 21
#include <iostream>
using namespace std;
void main()
{
int a,b;
cout<<"nhap so a :
";
cin>>a;
cout<<"nhap so b :
";
cin>>b;
cout<<"tong : "<<a+b<<"
";
cout<<"hieu : "<<a-b<<"
";
cout<<"tich : "<<a*b<<"
";
cout<<"tong : "<<(float)a/b<<"
";
}
bai 22
#include <iostream>
using namespace std;
void main()
{
int a,b,c,d;
cout<<"a: ";
cin>>a;
cout<<"b: ";
cin>>b;
cout<<"c: ";
cin>>c;
cout<<"d: ";
cin>>d;
cout<<"trung bing cong : "<<(float)(a+b+c+d)/4<<"
";
}
bai 23
#include <iostream>
using namespace std;
void main()
{
int a,b;
cout<<"a : ";
cin>>a;
cout<<"b : ";
cin>>b;
cout<<" so lon nhat la ";
if (a>b)
cout<<a<<endl;
else cout<<b<<endl;
}
bai 24
#include <iostream>
using namespace std;
void main()
{
int a,b,c;
cout<<"a : ";
cin>>a;
cout<<"b : ";
cin>>b;
cout<<"c : ";
cin>>c;
cout<<" so lon nhat la ";
if (a>b&&a>c)
cout<<a;
else
if (b>a&&b>c)
cout<<b;
else cout<<c;
}
bai 25:
#include <iostream>
using namespace std;
void main()
{
int a,b,c;
cout<<"a :";
cin>>a;
cout<<"b :";
cin>>b;
cout<<"c :";
cin>>c;
cout<<" so tang da la :";
if(a>b&&a>c)
if (b>c)
cout<<c<<b<<a;
else cout<<b<<c<<a;
else
if (b>a&&b>c)
if (a>c)
cout<<c<<a<<b;
else cout<<a<<c<<b;
else
if (c>b&&c>a)
if (a>b)
cout<<b<<a<<c;
else cout<<a<<b<<c;
}
bai 26
#include<iostream>
using namespace std;
void main()
{
int a,b,x;
cout<<"nhap cac phan tu trong phuong trinh Ax + B =0
";
cout<<"A :";
cin>>a;
cout<<"B :";
cin>>b;
if (a==0)
cout<<"phuong trinh vo nghiem !!";
else
cout<<" nghiem phuong trinh la :";
if (b==0)
cout<<"x = 0";
else cout<<(float)(-b)/a;
}
bai 27
#include<iostream>
#include<math.h>
using namespace std;
void main()
{
float a,b,c,x,d;
cout<<"nhap cac phan tu trong phuong trinh Axx + Bx +C =0
";
cout<<"A :";
cin>>a;
cout<<"B :";
cin>>b;
cout<<"C :";
cin>>c;
d=(b*b)-4*a*c;
if (a==0)
cout<<"nghiem phuong trinh la : "<<(-c)/b<<"
";
else
if (d<0)
cout<<" phuong trinh vo nghiem";
else
if (d==0)
cout<<"phuong trinh co nghiem kep : pt co 2 nghiem : x1=\t"<<(-b-sqrt(d))/(2*a)<<endl<<" \t\tva x2=\t"<<(-b+sqrt(d))/(2*a)<<endl;
}
bai 30
#include<iostream>
using namespace std;
void main()
{
int n,t,c,d,max,min;
cout<<"nhap vao so nguyen co 3 chu so: ";
cin>>n;
t=n/100;
c=(n%100)/10;
d=n%10;
max=t;
if(d>max)
max=d;
if(c>max)
max=c;
min=t;
if(d<min)
min=d;
if(c<min)
min=c;
cout<<min<<(t+c+d)-(min+max)<<max<<endl;
}
bai 31
#include<iostream>
using namespace std;
void main()
{
int dd,mm,yy;
cout<<"nhap vao ngay : ";
cin>>dd;
cout<<"nhap vao thang : ";
cin>>mm;
cout<<"nhap vao nam : ";
cin>>yy;
if(dd==0)
cout<<"sai ngay";
if(mm==0)
cout<<"sai thang";
if(yy==0)
cout<<"sai nam";
if(mm==1||mm==3||mm==5||mm==7||mm==8||mm==10||mm==12)
if(dd>31)
cout<<"sai thang!!";
if(mm==4||mm==6||mm==9||mm==11)
if(dd>30)
cout<<"sai thang!!";
if (yy/4==0)
if(mm==2)
if(dd>29)
cout<<"sai ngay !!";
if (yy/4!=0)
if(mm==2)
if(dd>=29)
cout<<"sai ngay !!";
}
bai 41:
// uoc so cua 1 so
#include<iostream>
using namespace std;
void main()
{
int n,i,dem;
cout<<"moi nhap n : ";
cin>>n;
//neu muon in ra so uoc thi them vao o day chu dem==;
for(i=1;i<=n;i++)
if(n%i==0)
//dem++;
cout<<"uoc so la : " <<i<<endl; //thay o day la dem
}
bai 54:
// s=1+[(1+2)/2!]+[(1+2+3)/3!]
#include<iostream>
using namespace std;
void main ()
{
float i,t,m,s,n;
cout<<" nhap n : " ;
cin >>n ;
t=0;
m=1;
s=0;
for(i=1;i<=n;i++)
{
t=t+i;
m=m*i;
s=s+(t/m);
}
cout<<s<<endl;
}
bai 57:
//s=1+(1+2)+(1+2+3)
#include<iostream>
using namespace std;
void main ()
{
int i,s,p,n;
cout<<" nhap n : " ;
cin >>n ;
p=0;
s=0;
for(i=1;i<=n;i++)
p=p+i;
s=s+p;
cout<<s<<endl;
}
bai 58:
// fibonaci 1 1 2 3 5 8
#include<iostream>
using namespace std;
void main ()
{
int i,n,f,fa,fb;
cout<<" nhap n: " ;
cin >>n;
cout<<" 1 1 ";
fa=1;
fb=1;
for (i=2;i<=n;i++)
{
f=fa+fb;
cout<<f<<" ";
fb=fa;
fa=f;
}
if (fa>=fb)
f=fa+fb;
cout<<f<<" ";
fa=fb;
fb=f;
}
Bạn đang đọc truyện trên: Truyen247.Pro