viet phuong trinh tao tep so.txt gom n so nguyen duong chan
viet phuong trinh su dung bien mang phap 10 phan tu kieu so nguyen in ra mang hinh so chan
viet chuong trinh nhap vao so mguyen n va day so gom n la so nguyen tu ban phim in ra man hinh so lon nhat trong day so nguyen vua nhap
Lời giải :
program hotrotinhoc ;
var a: array[1..32000] of integer ;
i,n,max : integer ;
begin
write('Nhap n='); readln(n);
writeln('Nhap gia tri cua cac phan tu');
for i:= 1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:= 1 to n do if max<a[i] then max:=a[i];
write('So lon nhat la:',max');
readln
end.
Tim mot so chan lon nhat co 5 chu so ma 3 chu so dau giu nguyen gia tri tu trai sang phai tao thanh mot so chinh phuong va 3 chu so cuoi giu nguyen thu tu tao thanh 1 lap phuong dung
viet chuong trinh nhap so n nguyen duong (n<=100) sau do tinh tong cai so tu 1 den N viet ket qua ra man hinh
var s,i,n:integer;
begin
Write('n = ');
While (n > 100) and (n < 1) then
Begin
write('Nhap sai, nhap lai ');readln(n);
End;
for i:=1 to n do
s:=s+i;
write('tong la: ',s);
readln;
end.
1) Viet chuong trinh nhap xau S1, tao xau S2 gom tat ca cac chu so cua xau S1
#include <bits/stdc++.h>
using namespace std;
string s1;
int d,i;
int main()
{
getline(cin,s1);
d=s1.length();
for (i=0; i<=d-1; i++)
if ((s1[i]>=48) and (s1[i]<=57)) cout<<s1[i];
return 0;
}
1)Viet tap hop B gom can so la tich cua dung 3 so Nguyen to co 1 chu so
2) Viet tap hop A gom cac so chan co 4 chu so va co tich cac chu so bang 10
viet chuong trinh nhap 1 so nguyen khac khong tu ban phim,viet ra man hinh cac so tu nhien chan
uses crt;
var n,i:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n>0;
write('Cac so chan trong khoang tu 1 toi ',n,' la: ');
for i:=1 to n do
if i mod 2=0 then write(i:4);
readln;
end.
program so_tu_nhien_chan;
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
write('Cac so chan nho hon hoac bang ',n,' la: ');
for i:=2 to n do
if i mod 2=0 then write(i:4,' ;');
readln;
end.
viet phuong trinh nhap vao mang a gom N(N<=100) cac so nguyen roi thuc hien cac yeu cau
1. in ra danh sach cac so chia het cho 4
2. in ra mang hinh gia tri lon nhat chia het cho 7 va chi so do
3. xuat ra mang hinh cac phan tu cua mang do theo thu tu giam dan
uses crt;
var a,b:array[1..100]of integer;
n,i,dem,max,tam,j:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=100);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Cac so chia het cho 4 la: ');
for i:=1 to n do
if a[i] mod 4=0 then write(a[i]:4);
writeln;
dem:=0;
for i:=1 to n do
if a[i] mod 7=0 then
begin
inc(dem);
b[dem]:=a[i];
end;
max:=b[1];
for i:=1 to dem do
if max<b[i] then max:=b[i];
writeln('So lon nhat chia het cho 7 la: ',max);
writeln('Cac chi so cua no trong day A la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('Day so sau khi sap xep giam dan la: ');
for i:=1 to n do
write(a[i]:4);
readln;
end.
viet 5 so thap phan gom toan cac chu so chan khac nhau va phan nguyen co mot chu so :
1,2345678
2,4357656
3,3456543
4,4963476
5,8632549
đúng thì k nha