bai tap

bai' 1:

#include<iostream>

using namespace std;

int dem(int [],int);

int Tong(int [],int);

int main(){

int n,i,max,min;

cout << "n = ";

cin >> n;

int a[n];

for(int i=0;i<n;i++){

cout << "a[" << i << "] = ";

cin >> a[i];

}

max=0;

min=0;

for(i=1;i<n;i++){

if(a[max]<a[i]){

max=i;

}else if(a[min]>a[i]){

min=i;

}

}

cout << "Phan tu nho nhat: " << a[min] << endl;

cout << "Phan tu lon nhat: " << a[max] << endl;

cout << "Tong cac phan tu chan: " << Tong(a,n) << endl;

cout << "So phan tu le: " << dem(a,n) << endl;

system("pause");

return 0;

}

int dem(int a[],int n){

int so=0;

for(int y=0;y<n;y++){

if(a[y]%2!=0){

so++;

}

}

return so;

}

int Tong(int a[], int n){

int tong=0;

for(int x=0;x<n;x++){

if(a[x]%2==0){

tong+=a[x];

}

}

return tong;

}

bai' 2: pascal

#include<iostream>

using namespace std;

double GT(int n){

int i;

long double gt;

for(i=1,gt=1;i<=n;i++){

gt = gt*i;

}

return gt;

}

int TH(int k, int n){

double th=GT(n)/(GT(k)*GT(n-k));

return th;

}

int main(){

long double gt;

int n,i,j;

cout << "n = ";

cin >> n;

for(i=0;i<=n;i++){

double a[i];

for(j=0;j<=i;j++){

a[j]=TH(j,i);

cout << a[j] << " ";

}

cout << endl;

}

system("pause");

return 0;

}

bai' 3:

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

int m,n;

cout << "m = ";

cin >> m;

cout << "n = ";

cin >> n;

int a[m][n];

int b[m][n];

for(int i=0;i<m;i++){

for(int j=0;j<n;j++){

cout << "a[" << i << "][" << j << "] = ";

cin >> a[i][j];

}

}

cout << endl;

for(int i=0;i<m;i++){

for(int j=0;j<n;j++){

cout << "b[" << i << "][" << j << "] = ";

cin >> b[i][j];

a[i][j]+=b[i][j];

}

}

cout << endl;

for(int i=0;i<m;i++){

for(int j=0;j<n;j++){

cout << setw(1) << a[i][j] << " ";

}

cout << endl;

}

system("pause");

return 0;

}

bai' 4:

#include<iostream>

#include<iomanip>

#include<string>

using namespace std;

void nhap(int a[100][100],int m,int n,char x){

for(int i=0;i<m;i++){

for(int j=0;j<n;j++){

cout << x << "[" << i << "][" << j << "] = ";

cin >> a[i][j];

}

}

cout << endl;

}

int main(){

int m,n,k;

cout << "m = ";

cin >> m;

cout << "n = ";

cin >> n;

cout << "k = ";

cin >> k;

int a[100][100];

int b[100][100];

int c[100][100];

nhap(a,m,n,'a');

nhap(b,n,k,'b');

for(int i=0;i<m;i++){

for(int j=0;j<k;j++){

c[i][j]=0;

for(int l=0;l<n;l++){

c[i][j]=c[i][j]+(a[i][l]*b[l][j]);

}

}

}

for(int i=0;i<m;i++){

for(int j=0;j<k;j++){

cout << setw(2) << c[i][j] << " ";

}

cout << endl;

}

system("pause");

return 0;

}

bai' 5:

#include<iostream>

#include<string.h>

#include<iomanip>

using namespace std;

int main(){

int m;

char s[128];

cout << "s = ";

cin >> s;

int n;

n=strlen(s);

for(int i=0;i<(n/2);i++){

if(s[i]!=s[n-i-1]){

m=0;

break;

}

else{

m=1;

}

}

if(m==1){

cout << "Doi xung" << endl;

}else{

cout << "Khong doi xung" << endl;

}

system("pause");

return 0;

}

bai' 6:

#include<iostream>

#include<string>

#include<iomanip>

using namespace std;

int main(){

char a[128];

cout << "Names = ";

cin >> a;

int n=strlen(a);

for(int j=0;j<n;j++){

if(a[j]=='x'){

continue;

}

cout << a[j];

}

system("pause");

return 0;

}

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #afa