0% found this document useful (0 votes)
26 views10 pages

TH 1

The document contains multiple C++ code snippets that perform various tasks such as calculating the value of pi, summing series, counting prime numbers in a matrix, and validating string formats. Each code segment includes user input and output operations, along with loops and conditionals to achieve their respective functionalities. Overall, the document showcases different programming techniques and algorithms in C++.

Uploaded by

Ngoc Anh Duong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views10 pages

TH 1

The document contains multiple C++ code snippets that perform various tasks such as calculating the value of pi, summing series, counting prime numbers in a matrix, and validating string formats. Each code segment includes user input and output operations, along with loops and conditionals to achieve their respective functionalities. Overall, the document showcases different programming techniques and algorithms in C++.

Uploaded by

Ngoc Anh Duong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

#include <iostream>

#include <math.h>

using namespace std;

int main(){

int n;

cin>>n;

double s=0;

if(n>1000){

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

s= s+pow(-1,i)/(2*i+1);

double pi=s*4;

cout<<pi;

TỔNG

#include<iostream>

#include<math.h>

#include<iomanip>

using namespace std;

int main(){

int n;

double x;

cout<<"x= ";
cin>>x;

cout<<"n= ";

cin>>n;

int i;

double s=1;

double ptu;

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

ptu= pow(x,(2*i+1))/(2*i+1);

s=s+ptu;

cout<<fixed<< setprecision(3)<<s ;

return 0;

KHẢO CỔ

#include<iostream>

#include<math.h>

using namespace std;

int main(){

int A[100][100];

int n,m;

cin>>n>>m;

int i,j;

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

do{

cin>>A[i][j];

} while(A[i][j]<0 ||A[i][j]>100);

int t=0;

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

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

if(A[i][j]==0){

t++;

cout<<t;

return 0;

Thùng hóa chất

#include<iostream>

#include<cmath>

using namespace std;

int main(){

int n,i;

double A[1000];

double x;
cin>>n>>x;

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

cout<<"A["<<i<<"]";

cin>> A[i];

int day=0;

int het=0;

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

if(A[i]==x){

day++;

if(A[i]==0){

het++;

int voi= n-day-het;

cout<< "so thung day"<<day<<endl;

cout<< "so thung het"<<het<< endl;

cout<< "so thung voi"<< voi;

return 0;

Số l cần thêm để đầy

double s=0;

double ptu;

for(i= 1;i<=n;i++){
if(A[i]!=0 && A[i]!=x){

ptu=x-A[i];

s=s+ ptu;

cout<< s;

double s=0;

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

s= s+ A[i];}

cout<<"s= "<<s<< endl;

int thuong=s/x;

int dothem= n- thuong;

cout<< "dothem= "<<dothem;

Đếm số ngto trong mảng

#include<iostream>

#include<cmath>

using namespace std;

int main(){

int a[100][100];

int n,m,i,j;

cin>>n>>m;

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

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

cout<<"Nhap a["<<i<<"]["<<j<<"]";
cin>>a[i][j];

int dem =0;

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

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

bool check=true;

for(int k=2;k<= sqrt(a[i][j]); k++){

if(a[i][j] %k ==0){

check= false;

if( check){

dem++;

}}

cout<<'\n'<<"So luong ngto: "<<dem;

return 0;

#include<iostream>

using namespace std;

int main()
{

int n;

cin >>n;

float Sn=0;

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

int Sm=0;

for(int j=1;i<=i;j++){

Sm=Sm+j;

float phantu = 1.0/Sm;

Sn= Sn+ phantu;

cout<< Sn;

return 0;

Thử hóa chất

#include<iostream>

using namespace std;

int main(){

int n,i;

double A[1000];

double B[1000];

cin>>n;

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

cout<<"A["<<i<<"]";

cin>> A[i];

} while (A[i]<1 || A[i]> 10000);

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

do{

cout<<"B["<<i<<"]";

cin>> B[i];

} while (B[i]<0 || B[i]> A[i]);

int day=0;

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

if(A[i]==B[i]){

day++;}

} cout<<day;

Số thùng đổ để đầy

int j;

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

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

if(A[i]>A[j]){

swap (A[i],A[j]);

}
}

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

cout<<A[i]<< " ";

int dem=0;

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

if(A[i]<voi){

voi= voi-A[i];

else{ dem++;}

cout<<'\n'<<dem ;

#include<iostream>

#include<string>

using namespace std;

int main(){

string s;

getline(cin,s);

if(s.length()==11){

// kiem tra tiep

if(
(s[0]>= '0' and s[0]<='9') and

(s[1]>= '0' and s[1]<='9') and

s[2]=='-' and

((s[3]>='a' and s[3]<= 'z') or

(s[3]>='A' and s[3]<= 'Z')) and

(s[4]>= '0' and s[4]<='9') and

(s[5]>= '0' and s[5]<='9') and

(s[6]>= '0' and s[6]<='9') and

( s[7]>= '0' and s[7]<='9') and

(s[8]=='.') and

(s[9]>= '0' and s[9]<='9') and

(s[10]>= '0' and s[10]<='9')

cout<<" yes";

else {

cout<< "No";}

You might also like