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

For While

The document contains 12 programming problems in Vietnamese that involve basic concepts like loops, conditionals, arrays, finding maximum/minimum values, prime numbers, GCD, LCM, password validation, and summing odd numbers. Each problem is a short 1-10 line C or C++ program to solve a basic mathematical or logical problem.

Uploaded by

ya0058466
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)
17 views10 pages

For While

The document contains 12 programming problems in Vietnamese that involve basic concepts like loops, conditionals, arrays, finding maximum/minimum values, prime numbers, GCD, LCM, password validation, and summing odd numbers. Each problem is a short 1-10 line C or C++ program to solve a basic mathematical or logical problem.

Uploaded by

ya0058466
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

Bài 1

include<stdio.h>
int main(){
int sum=0;
int i;
int a;
printf("nhap so a ");
scanf("%d", &a);
for( int i=2;i<=a;i++){
sum +=i;
}
int tong = sum + 2*a;
printf("%d",tong);
}
Bài 2
#include <bits/stdc++.h>
int main(){
float a,b;
printf("nhap n = ");
scanf("%f",&a);
for (int i= 2 ; i<=a; i++){
b += 1.0/i;
} printf("tong = %.2f",b);
return 0;
}
Bài 3
#include <stdio.h>
#include <math.h>
int main(){
int n;
printf("\nNhap n = ");
scanf("%d", &n);
if(n < 2){
printf("\n%d khong phai so nguyen to", n);
return 0;
}
int t = 0;
for(int i = 2; i <= sqrt(n); i++){
if(n % i == 0){
t++;
}
}
if(t == 0){
printf("\n%d la so nguyen to", n);
}else{
printf("\n%d khong phai so nguyen to", n);
}
}

Bài 4
#include<bits/stdc++.h>
int main() {
for (int n = 1; n < 1000; ++n) {
int t = 0;
for (int i = 2; i <= sqrt(n); i++){
if (n % i == 0){
t++;
}
}
if (t == 0 && n > 1){
printf("%d\t", n);
}
return 0;
}
Bài 5
#include<bits/stdc++.h>
int main(){
int a,b;
printf("nhap so a ");
scanf("%d",&a);
printf("nhap so b ");
scanf("%d",&b);
if( a == 0 || b == 0){
printf("UCLN la %d", a+b);
}
while( a != b )
{
if (a > b){
a -= b;
}else{
b -= a;
}
}
printf("ucln la %d",a);
}
Bài 6
#include<bits/stdc++.h>
int main(){
int a,b,c,d;
printf("nhap a ");
scanf("%d",&a);
printf("nhap b ");
scanf("%d",&b);
if( a>b ){
c = a;
}else{
c = b;
}
for(int i = c ; i <= a*b ; i += c){
if( i%a==0 && i%b==0 ){
d = i;
break;
}
}printf("bcnn la %d",d);
}
Bài 7
#include<bits/stdc++.h>
int main(){
for ( int a = 1 ; a < 10 ; a++){
for ( int b = 1 ; b < 10 ; b++){
for ( int c = 1 ; c < 10 ; c++){
if ( a+b+c == a*b*c ){
printf("%d %d %d\n",a,b,c);
}
}
}
}
}
Bài 8
#include<bits/stdc++.h>
int main(){
int min , max , n;
printf("nhap so phan tu : ");
scanf("%d",&n);
int c[n];
for ( int i = 0 ; i < n ; i++ ){
printf("nhap phan tu %d:\n",i);
scanf("%d",&c[i]);
}
ma = c[0];
for ( int i = 0 ; i < n ; i++ ){
if ( c[i] > ma ){
ma = c[i];
}
}
mi = c[0];
for ( int i = 0 ; i < n ; i++ ){
if ( mi > c[i] ){
mi = c[i];
}
}
printf("max = %d\nmin = %d",ma,mi);
return 0;
}
Bài 9
#include<bits/stdc++.h>
int main(){
int a;
printf("nhap so nguyen duong : ");
scanf("%d",&a);
while( a <= 0 ){
printf("hay nhap so nguyen duong : ");
scanf("%d",&a);
}
if( a > 0 ){
for ( int i = 1 ; i <= a ; i++){
if ( i % 2 != 0 ){
printf("%d ",i);
}
}
}
return 0;
}
Bài 10
#include<bits/stdc++.h>
int main(){
int a, sum;
printf("nhap so nguyen duong : ");
scanf("%d",&a);
while( a <= 0 ){
printf("hay nhap so nguyen duong : ");
scanf("%d",&a);
}
if( a > 0 ){
for ( int i = 1 ; i <= a ; i++){
if ( i % 2 != 0 ){
sum += i;
}
}
}
printf("%d ",sum);
return 0;
}
Bài 11
#include<bits/stdc++.h>
int main(){
int a;
do{
printf("nhap mat khau : ");
scanf("%d",&a);
}
while( a != 1111 );
printf("mat khau dung !");
return 0;
}
Bài 12
#include<bits/stdc++.h>
int main(){
int a;
do{
printf("nhap so : ");
scanf("%d",&a);
}
while( a > 0 );
return 0;
}

You might also like