tapddv09
DE 1
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{float x,y;
cout<<"nhap x: ";
cin>>x;
cout<<"nhap y: ";
cin>>y;
cout<<"tong x+y ="<<x+y;
cout<<"
hieu x-y ="<<x-y;
cout<<"
tich x*y ="<<x*y;
cout<<"
thuong x:y ="<<x/y;
getch();
} DE 2
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int n;
cout<<"nhap n: ";
cin>>n;
if(n%2==0)
cout<<"n la so chan.";
else
cout<<"n la so le.";
getch();
} DE3
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int i,n;
long double p=1;
cout<<"nhap n: ";
cin>>n;
if(n==0)
cout<<"n!=1";
else
{for(i=1;i<=n;i++)
p=p*i;
cout<<"n!="<<p;
}
getch();
}
DE4
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int n,i,;
long s=0;
cout<<"nhap n: ";
cin>>n;
for(i=0;i<=n;i++)
s=s+i;
cout<<"tong :"<<s;
getch();
} DE 5
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int n,i;
long s=0;
cout<<"nhap n: ";
cin>>n;
for(i=0;i<=n;i++)
s=s+i*i;
cout<<"tong binh phuong la:"<<s;
getch();
} DE6
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{int n,i,;
long double s=0;
cout<<"nhap n: ";
cin>>n;
for(i=0;i<=n;i++)
s=s+i*pow(-1,i+1);
cout<<"tong la:"<<s;
getch();
}
De7
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{int n,i,;
long double s=0;
cout<<"nhap n: ";
cin>>n;
for(i=0;i<=n;i++)
s=s+i*pow(-1,i);
cout<<"tong la:"<<s;
getch();
} DE8
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{unsigned long m=0,n,a;
cout<<"nhap so nguyen duong n: ";
cin>>n;
n=n*10+1;
while(n!=0)
{m=m*10+n%10;
n=n/10;
}
cout<<"cac chu so cua n la: ";
while(m!=0)
{a=m%10;
m=m/10;
if(m!=1)
cout<<a<<",";
else
{cout<<a<<" ";
break;
}
}
getch();
} De9
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i;
long s=0;
cout<<"nhap so phan tu cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(i=0;i<n;i++)
s=s+a[i];
cout<<"tong cac phan tu la: ";
cout<<s;
getch();
}
DE10
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i;
long s=0;
cout<<"nhap so phan tu cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(i=0;i<n;i++)
{if(a[i]%2!=0)
s=s+a[i];
}
if(s==0)
cout<<"mang ko co phan tu le.";
else
cout<<"tong cac phan tu le la: "<<s;
getch();
} DE11
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i;
long s=0;
cout<<"nhap so phan tu cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(i=0;i<n;i++)
{if(a[i]%2==0)
s=s+a[i];
}
if(s==0)
cout<<"mang ko co phan tu chan.";
else
cout<<"tong cac phan tu chan la: "<<s;
getch();
} De12
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i,j;
cout<<"nhap so phan tu n cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<"nhap vi tri can xoa: ";
cin>>j;
for(i=0;i<n-1;i++)
{if(i<j-1)
a[i]=a[i];
else
a[i]=a[i+1];
}
cout<<"mang moi sau khi xoa: "<<"[ ";
for(i=0;i<n-1;i++)
cout<<a[i]<<" ";
cout<<"]";
getch();
De13
Chen 555
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i,j;
cout<<"nhap so phan tu n cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<"nhap vi tri can chen: ";
cin>>j;
a[j-1]=555;
cout<<"mang moi sau khi chen la: "<<"[ ";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<"]";
getch();
} DE14
L? l?n nh?t c?a m?ng
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i,max,j=0;
cout<<"nhap so phan tu n cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(i=0;i<n;i++)
if(a[i]%2!=0)
{a[j]=a[i];
j++;
}
if(j= =0)
cout<<"mang ko co phan tu le.";
else
{max=a[0];
for(i=1;i<j;i++)
if(max<a[i])
max=a[i];
cout<<"phan tu le lon nhat la: ";
cout<<max;
}
getch();
} DE15_16\
CH?n nh? nh?t c?a m?ng
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i,min,j=0;
cout<<"nhap so phan tu n(n>2) cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(i=0;i<n;i++)
if(a[i]%2==0)
{a[j]=a[i];
j++;
}
if(j==0)
cout<<"mang ko co phan tu chan.";
else
{min=a[0];
for(i=1;i<j;i++)
if(min>a[i])
min=a[i];
cout<<"phan tu chan nho nhat la: ";
cout<<min;
}
getch();
}
DE17
Xu?t ph?n t? l? âm..
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int a[100];
int n,i;
cout<<"nhap so phan tu cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<"cac phan tu chan la: ";
for(i=0;i<n;i++)
if(a[i]%2==0)
cout<<" "<<a[i];
cout<<"
cac phan tu le la: ";
for(i=0;i<n;i++)
if(a[i]%2!=0)
cout<<" "<<a[i];
cout<<"
cac phan tu am la: ";
for(i=0;i<n;i++)
if(a[i]<0)
cout<<" "<<a[i];
cout<<"
cac phan tu ko am la: ";
for(i=0;i<n;i++)
if(a[i]>0)
cout<<" "<<a[i];
getch();
} DE18
Nh?p xu?t m?ng
#include<iostream>
#include<conio.h>
using namespace std;
void nhapmang(int a[ ],int &n);
void xuatmang(int a[ ],int &n);
int main()
{
int a[100];
int n;
nhapmang(a,n);
cout<<"cac phan tu cua mang la: ";
xuatmang(a,n);
getch();
}
void nhapmang(int a[ ],int &n)
{cout<<"nhap so phan tu cua mang: ";
cin>>n;
for(int i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
}
void xuatmang(int a[],int &n)
{cout<<"[";
for(int i=0;i<n;i++)
cout<<" "<<a[i];
cout<<" ]";
} DE19
T?ng ph?n t? m?ng
#include<iostream>
#include<conio.h>
using namespace std;
void tongmang(int a[],int &n);
int main()
{int a[100];
int n,i;
cout<<"nhap so phan tu cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<"tong cac phan tu la: ";
tongmang(a,n);
getch();
}
void tongmang(int a[ ],int &n)
{long s=0;
int i;
for(i=0;i<n;i++)
s=s+a[i];
cout<<s;
}
De20
#include<iostream>
#include<conio.h>
using namespace std;
void timx(int a[],int n,int x);
int main()
{int a[100];
int x,n,i;
cout<<"nhap so phan tu cua mang: ";
cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<"nhap gia tri can tim trong mang: ";
cin>>x;
cout<<"vi tri tim thay x la: ";
timx(a,n,x);
getch();
}
void timx(int a[ ],int n,int x)
{int i;
for(i=0;i<n;i++)
if(a[i]= =x)
cout<<" "<<i;
} De21
Xu?t ra s? t? chong chu?i
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{char s[100];
int i,d=1;
cout<<"nhap mot chuoi ky tu: ";
fflush(stdin);
gets(s);
for(i=0;i<strlen(s);i++)
if(s[i]==' '&&s[i+1]!=' ')
d++;
cout<<"so tu cua chuoi vua nhap la: ";
cout<<d<<" tu";
getch();
} De22_23
In hoa kí t? d?u c?a m?i t?
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{char s[100];
int i;
cout<<"nhap mot chuoi ky tu: ";
fflush(stdin);
gets(s);
strlwr(s);
s[0]=s[0]-('a'-'A');
for(i=1;i<strlen(s);i++)
if(s[i]!=' '&&s[i-1]==' ')
s[i]=s[i]-('a'-'A');
cout<<"chuoi in hoa dau moi tu la: ";
cout<<s;
getch();
}
DE24
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
void timkytu(char s[ ],char a);
int main()
{char s[100];
char a;
cout<<"nhap mot chuoi ky tu: ";
fflush(stdin);
gets(s);
cout<<"nhap ky tu can tim: ";
cin>>a;
cout<<"so lan ky tu xuat hien la: ";
timkytu(s,a);
getch();
}
void timkytu(char s[ ],char a)
{int i,d=0;
for(i=0;i<strlen(s);i++)
if(s[i]==a)
d++;
cout<<d;
} DE25_26
Chi?u dài chu?i
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
void chieudaichuoi(char s[ ]);
int main()
{char s[100];
cout<<"nhap mot chuoi ky tu: ";
fflush(stdin);
gets(s);
cout<<"chieu dai chuoi vua nhap la: ";
chieudaichuoi(s);
cout<<" ky tu.";
getch();
}
void chieudaichuoi(char s[ ])
{int n;
n=strlen(s);
cout<<n;
} DE27
N?i S2 vào s1
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{char s1[100];
char s2[100];
cout<<"nhap chuoi ky tu s1: ";
fflush(stdin);
gets(s1);
cout<<"nhap chuoi ky tu s2: ";
gets(s2);
strcat(s1,s2);
cout<<"chuoi s1 sau khi noi chuoi s2 la: ";
cout<<s1;
getch();
}
DE28
Chèn ch vào cuoi tu dau tiên chu?i 1
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{char s1[100],s2[100];
int a,i=0,d=0;
cout<<"nhap chuoi s1: ";
fflush(stdin);
gets(s1);
cout<<"nhap chuoi s2 can chen: ";
gets(s2);
cout<<"chen chuoi s2 vao ";
cout<<" chuoi s1 sau tu thu: ";
cin>>a;
cout<<"Ta co chuoi moi: ";
while(s1[i]!='\0')
{if(s1[i]= =' ')
{d++;
if(d= =a)
cout<<" "<<s2;
}
cout<<s1[i];
i++;
}
getch();
} DE29
Cách nhau d?u ph?y
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{char s[100];
int i;
cout<<"nhap mot chuoi ky tu: ";
fflush(stdin);
gets(s);
cout<<"cac tu cua chuoi la: ";
for(i=0;i<strlen(s);i++)
{if(s[i]==' ')
cout<<", ";
else
cout<<s[i];
}
getch();
} DE30
Chu?i d?o
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{char s1[100],s2[100];
int i=0,j;
cout<<"nhap mot chuoi ky tu: ";
fflush(stdin);
gets(s1);
cout<<" chuoi dao nguoc la: ";
j=strlen(s1);
while(j!=0)
{s2[i]=s1[j-1];
cout<<s2[i];
j--;
i++;
}
getch();
}
Bạn đang đọc truyện trên: Truyen247.Pro