for (thiết lập ban đầu; điều kiện lặp; bước tăng/giảm) { khối lệnh; }
#include <iostream> #include <conio.h> using namespace std; int main() { int n; // nhap n cout<<"\n n = "; cin>>n; // tinh tong int s = 0; for(int i=0; i<=n; i++) s = s+i; // in ket qua cout<<"\n Tong = "<<s; return 0; }
#include <iostream> #include <conio.h> using namespace std; int main() { int n; // nhap n cout<<"\n n = "; cin>>n; // dem so chan int dem = 0; for(int i=0;i<=n;i++) if (i%2==0) dem++; // in ket qua cout<<"\n Ket qua = "<<dem; return 0; }
#include <iostream> #include <conio.h> using namespace std; int main() { cout<<"In ket qua:\n"; for(int i=1000;i<=9999;i++) { if(i%10+(i/10)%10+(i/100)%10+i/1000==10) cout<<i<<";\t"; } return 0; }
#include <iostream> #include <conio.h> using namespace std; int main() { cout<<"In bang cuu chuong: \n"; for(int i=1;i<=9;i++) { for(int j=1;j<9;j++) cout<<i<<"x"<<j<<"= "<<i*j<<";\t"; cout<<"\n"; } return 0; }
#include <iostream> #include <conio.h> using namespace std; int main() { cout<<"In so nguyen to nho hon 1000: \n"; for(int i=1;i<=1000;i++) { int test = 0; for(int j=2;j<i;j++) if(i%j==0) { test=1; break; } if(test==0) cout<<i<<";\t"; } return 0; }
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!