#include <iostream> #include <cstdlib> using namespace std; //khai báo kieu du lieu struct phanso { int tuso; int mauso; }; typedef struct phanso PHANSO; void NhapPS(PHANSO &x ); void XuatPS(PHANSO x); PHANSO TongHaiPS( PHANSO a, PHANSO b); PHANSO TichHaiPS( PHANSO a, PHANSO b); PHANSO ThuongHaiPS( PHANSO a, PHANSO b); int …
Xem tiếpChương Trình nhập mảng không trùng, xuất mảng, in số chính phương tại vị trí lẻ, in vị trí các phần tử lớn nhất, tổng các phần tử tại vị trí chẳn, xếp mảng tăng
#include <iostream> #include <cstdlib> using namespace std; void NhapMang(int a[],int n); void XuatMang(int a[],int n); void XepMangTang(int a[],int n); void SoChinhPhuongVTLe(int a[],int n); void VTPhanTuLonNhat(int a[],int n); int TongTaiVTChan(int a[],int n); int main() { int n,a[100]; cout<<“nhap n: “; cin>>n; NhapMang(a,n); XuatMang(a,n); cout<<“So chinh phuong tai vi tri le”<<endl; SoChinhPhuongVTLe(a,n); …
Xem tiếpĐếm số lượng chử số dương nhỏ nhất của mảng
#include <iostream> #include <cstdlib> using namespace std; void NhapMang(int a[],int n); void XuatMang(int a[],int n); int DemSoDuongNhoNhat(int a[],int n); int main() { int n,a[100],dem; cout<<“nhap n: “; cin>>n; NhapMang(a,n); XuatMang(a,n); dem=DemSoDuongNhoNhat(a,n); if(dem==-1) cout<<“Mang khong ton tai so duong”; else cout<<“So luong chu so duong nho nhat trong mang la: “<<dem<<endl; …
Xem tiếpSắp xếp mãng một chiều tăng dần
include <iostream> #include <cstdlib> using namespace std; void NhapMang(int a[],int n); void XuatMang(int a[],int n); void XepMangTang(int a[],int n); int main() { int n,a[100]; cout<<“nhap n: “; cin>>n; NhapMang(a,n); XuatMang(a,n); XepMangTang(a,n); cout<<“Mang sau khi xep tang dan”<<endl; XuatMang(a,n); return 0; } void NhapMang(int a[],int n) { for(int i=0;i<n;i++) { …
Xem tiếpNhập n và xuất số chẵn .
#include <iostream> int main() { int n; printf (“nhap n:”); scanf(“%d”,&n); for (int i = 2; i <= n; i+=2) printf(“so chan la:%d”,i); }
Xem tiếpNhập mảng và xuất giá trị âm
#include<stdio.h> void Nhapmang(int a[],int&n) { for(int i=0;i<n;i++) { printf(“nhap a[%d]”,i); scanf(“%d”,&a[i]); } } void Xuatmang(int a[],int n) { for (int i=0;i<n;i++) printf(“%4d”,a[i]); } int ViTriAm(int a[],int n) { for (int i=0; i<n;i++) if(a[i]<0) printf(“\nvi tri am la:%d”,i); } int main() { int n,a[100],i; printf(“nhap n:”); scanf(“%d”,&n); Nhapmang(a,n); //Xuatmang(a,n); ViTriAm(a,n); }
Xem tiếpNhập vào số có 2 chữ số, và xuất ra cách đọc
#include <stdio.h> int main() { int n; printf(“Nhap so nguyen n co 2 chu so: “); scanf(“%d”, &n); if(9<n && n<100) { switch(n/10) { case 1: printf(“Muoi “); break; case 2: printf(“Hai Muoi “); break; case 3: printf(“Ba Muoi “); break; case 4: printf(“Bon Muoi “); break; case 5: printf(“Nam …
Xem tiếpViết chương trình giải : Sn=1^2+2^2+………+n^2
#include<stdio.h> #include <math.h> int main () { int n,i=1; float S=0; printf(“nhap n=”); scanf (“%d”,&n); while(i<=n) { S+=(i*i); i++; } printf (“tong = %d”,S); }
Xem tiếpSử dụng mảng để nhập các phần tử và thực hiện các yêu cầu liên quan đến mảng
#include<conio.h> #include<stdio.h> void Nhapmang(int a[],int&n) { for(int i=0;i<n;i++) { printf(“nhap a[%d]”,i); scanf(“%d”,&a[i]); } } void Xuatmang(int a[],int n) { for (int i=0;i<n;i++) printf(“%4d”,a[i]); } void ChiaHetBa (int a[],int n) { for(int i=0;i<n;i++) if(a[i]%3==0) printf( “\nso chia het cho 3 la :%d”,a[i]); } void SoLuongDuong (int a[], int n,int dem=0) …
Xem tiếp
Sử dụng mảng, để nhập số nguyên gồm n phần tử (0
#include<stdio.h> #include<conio.h> void Nhapmang(int a[],int&n) { for(int i=0;i<n;i++) { printf(“nhap a[%d]”,i); scanf(“%d”,&a[i]); } } void Xuatmang(int a[],int n) { for (int i=0;i<n;i++) printf(“%4d”,a[i]); } int main() { int n, a[10]; do{ printf(“nhap so phan tu 0<sl<10:”); scanf(“%d”,&n); } while (n<=0||n>10); Nhapmang(a,n); Xuatmang(a,n); return 0; }
Xem tiếpNhập thông tin sinh viên . Xuất thông tin ,tìm sinh viên , đếm số lượng sinh viên có dtb <5 ,sắp xếp tăng dần theo dtb .
#include<stdio.h> #include<math.h> #include<string.h> #define MAX 100 struct date { int ngay, thang, nam; }; void nhapdate(date &a) { printf(“Nhap ngay thang nam sinh (dd/mm/yyyy): “); scanf(“%d%*c%d%*c%d”,&a.ngay,&a.thang,&a.nam); } void xuatdate(date a) { printf(” Ngay sinh: %02d/%02d/%04d”,a.ngay,a.thang,a.nam); } struct ttsv { char MS[11]; char Ten[11]; date Sn; char lop[8]; char GT; float …
Xem tiếpĐịnh nghĩa kiểu dữ liệu nhiều phân số . Thực hiện nhập , xuất , rút gọn , tổng, so sánh , sắp xếp tăng dần , tìm phân số lớn nhất của nhiều phân số.
#include<stdio.h> #include<math.h> struct ttphanso { int tu; int mau; }; typedef struct ttphanso PS; //Nhap ps void Nhapps(PS &x) { printf (“\tNhap tu so: “); scanf (“%d”, &x.tu); do{ printf (“\tNhap mau so: “); scanf (“%d”, &x.mau); if (x.mau==0) printf(“\tNhap sai, nhap lai!: “); }while(x.mau==0); if(x.mau<0) { x.tu=-x.tu; x.mau=-x.mau; } …
Xem tiếpĐịnh nghĩa kiểu dữ liệu phân số. Thực hiện nhập, xuất, rút gọn, tổng 2 phân số.
#include<stdio.h> #include<conio.h> #include<math.h> struct phanso { int tu; int mau; }; void nhapphanso(phanso &ps); void xuatphanso(phanso ps); int ULCN(int a, int b); void rutgon(phanso &ps); phanso tongps(phanso x,phanso y); int main() { phanso x,y; printf(“\nNhap phan so thu nhat “); nhapphanso(x); xuatphanso(x); printf(“\nNhap phan so thu 2”); nhapphanso(y); xuatphanso(y); phanso …
Xem tiếpSử dụng mảng: nhập, xuất ,và tính tổng các vị trĩ chăn x, xuất ố chính phương ở vị trí lẻ , sắp xếp tăng dần .
#include #include void xuatmenu(int &chon) { printf(“\n \t 1: Xuat Mang “); printf(“\n \t 2: Xuat So Chinh Phuong “); printf(“\n \t 3: Xuat vi tri phan tu lon nhat “); printf(“\n \t 4: Tinh tong cac phan tu o vi tri chan”); printf(“\n \t 5: viet ham sap xep …
Xem tiếp