Anda di halaman 1dari 5

Huy Duy

Mssv:2011 1338
DDT04-K56

// 1_giaiptbac2.cpp : Defines the entry point for the console application.


//
#include "stdafx.h"
#include<iostream>
#include<math.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
double a,b,c,d;
cout<<"Nhap he so a,b,c:\n";cin>>a>>b>>c;
d=b*b-4*a*c;
if(d>=0)
{
if(d>0)
{
a=2*a;d=sqrt(d);
cout<<"x1="<<(-b+d)/a;
cout<<"\nx2="<<(-b-d)/a;
}
else
cout<<"Pt co nghiem kep x="<<-b/(2*a);
}
else
cout<<"Pt vo nghiem";
system("pause");
}

// 2_giaitamgiac.cpp : Defines the entry point for the console application.


//
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{while(1)
{int a,b,c;
cout<<"\nNhap 3 canh a, b, c: \n";cin>>a>>b>>c;
if(a>=b+c||b>=c+a||c>=a+b)
{cout<<"a,b,c khong la ba canh tam giac";break;}
int canh=((a==b)|(b==c)<<1|((c==a)<<2));
a*=a;b*=b;c*=c;
int goc=((c==a+b)|(a==b+c)<<1|(b==a+c)<<2);
cout<<"Tam giac ";
switch(goc<<4|canh)
{
case 0:cout<<"thuong";break;
case 7:cout<<"deu";break;
default:
if(canh) cout<<"can";
if(goc) cout<<"vuong";

Page 1

cout<<" tai " <<char(((goc|canh)>>1)+64);


}
}
system("pause");
}
// 3_matran.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
double m,n;
cout<<"Nhap cac chieu cua ma tran m*n\n\t";cin>>m>>n;
for(int i=1;i<=n;i++)
{
{
for(int j=1;j<=m;j++)
{cout<<i*j;cout<<"\t";}
}
cout<<"\n";
}

system("pause");
}
// 4_lichnam.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int ngay,thang,years,dy,i;
cout<<"
Nhap nam: ";cin>>years;
dy=years-2000;
i=(365*dy+(dy-1)/4)%7;
for(thang=1;thang<=12;thang++)
{switch(thang)
{
case 2: (dy%4)==0?(ngay=29):(ngay=28);break;
case 4: case 6: case 9:case 11: ngay=30;break;
default: ngay =31;
}
cout<<"*---------------------===-----------------------*";
cout<<"\n
Thang "<<thang;cout<<"\n";
cout<<"\nCN\tT2\tT3\tT4\tT5\tT6\tT7\n";
for(int k=1;k<=i;k++) cout<<'\t';
for(int j=1;j<=ngay;j++)
{
cout<<j;
if(i==6)

Page 2

{cout<<'\n';i=0;}
else
{cout<<'\t';i++;}
}
cout<<"\n";
}
system("pause");
}
// 5_mangchanle8.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<math.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])


{
int a[1000],i,c=0,l=0,t=0;
for( i=0;i<1000;i++)
a[i]=rand()%1000+1;
for(i=0;i<1000;i++)
{if(a[i]%2==0)
{c=c+1;
{if(a[i]%8==0) t=t+1;}
}
else l=l++;
}
cout<<"\n
So cac so chan la: "<<c;
cout<<"\n
So cac so le la: "<<l;
cout<<"\nSo cac so chia het 8 la: "<<t;
system("pause");
}
// 7_Nhp gi tr cho s, i s thnh s nguyn v gn cho bin a
//
#include "stdafx.h"
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])


{
char s[50];int a=0;
cout<<"Nhap xau ki tu:";cin>>s;
for(int i=0;s[i]!=0;i++)
{
if(s[i]<'0'||s[i]>'9') break;
else
a=a*10+(s[i]-48);
}

Page 3

cout<<a;
cout<<'\n';
system("pause");
}
// 8_xaukituchuthuong.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<string.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char s[50];int i;
cout<<"Nhap xau ki tu:";cin>>s;
for(i=0;s[i]!=0;i++)
{
if(s[i]>=65 && s[i]<=90)
s[i]=s[i]+32;
}
cout<<'\n';
cout<<s;cout<<'\n';
system("pause");
}
// 9_hamgiaiptbac2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
int findroot(double a,double b, double c)
{
double d=b*b-4*a*c;
double *x1,*x2;
if (d<0) return 0;
a*=2;
if(d=0) {*x1=*x2=-b/a;return 1;}
d=sqrt(d);
*x1=(-b-d)/a;
*x2=(-b+d)/a;
return 2;
}
int main()
{
double a,b,c;
while(1){
cout<<"Nhap cac he so a, b, c:";
cin>>a>>b>>c;
if(a==0) break;
// neu a=0 thi thoat
double *x1, *x2;
switch( findroot(a,b,c))
{

Page 4

case 0: cout<<"Pt vo nghiem"; break;


case 1: cout<<"Pt co nghiem kep"<<x1;break;
case 2: cout<<"Phuong trinh co 2 nghiem pb";
cout<<"x1="<<x1;cout<<'\n';
cout<<"x2="<<x2;
}
cout<<endl;
}
}

Page 5

Anda mungkin juga menyukai