Viết chương trình nhập vào số nguyên dương n bất kỳ. Xuất ra trên màn hình kết quả tổng của dãy số sau: A = 1 + 2 + 3 + 4 + … + n Input: n = 5 Output: A = 15
Viết chương trình nhập vào số nguyên n bất kỳ. Xuất ra trên màn hình kết quả n lần chữ ‘XIN CHAO’ có số thứ tự. Input: n = 4 Output: 1. XIN CHAO 2. XIN CHAO 3. XIN CHAO 4. XIN CHAO
uses crt;
var i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
writeln(i,'. XIN CHAO');
readln;
end.
Viết phương trình nhập một dãy nguyên A có N phần tử (N<=100). Tính và in ra màn hình tích các số lẻ trong dãy A. Input: 5 1 4 5 2 3. Output:15
tham khảo
Program Hotboy;
Uses crt;
Var A:array[1..100] of integer;
I,n : byte;
S:real;
Begin
Clrscr ;
S:=1;
Write('nhao so phan tu trong day'); readln(n);
For i:=1 to n do
Begin
Write('A[',i,']'); readln(A[i]);
End;
For i:=1 to n do
If A[i] mod 5 =0 then
S:=S* A[i] ;
Writeln('Tong cac phan tu chia het cho 5 trong mang la',S);
Readln
End.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
t:=1;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t*a[i];
writeln(t);
readln;
end.
viết chương trình nhập n số nguyên từ bàn phím (n<10^5) , in ra man hình tổng các số nguyên lẻ và dãy số trên sau khi đc sắp xếp tăng dần
INPUT OUTPUT
5 9
2 4 1 5 3 1 2 3 4 5
C++ ah
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int n;
std::cout << "Enter the number of integers (n < 10^5): ";
std::cin >> n;
std::vector<int> numbers(n); std::cout << "Enter " << n << " integers: "; for (int i = 0; i < n; ++i) { std::cin >> numbers[i]; } int sumOfOdd = 0; for (int i = 0; i < n; ++i) { if (numbers[i] % 2 != 0) { sumOfOdd += numbers[i]; } } std::sort(numbers.begin(), numbers.end()); std::cout << "Sum of odd integers: " << sumOfOdd << std::endl; std::cout << "Sorted sequence: "; for (int i = 0; i < n; ++i) { std::cout << numbers[i] << " "; } std::cout << std::endl; return 0;
}
```
Câu 1 viết chương trình nhập vào 1 dãy n số nguyên bất kỳ .In ra màn hình tổng các số chia hết cho 2
uses crt;
var i,n:integer;
t:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap n:');readln(n);
t:=0;
for i:=1 to n do
begin
write('a[',i,']=');readln(a[i]);
if a[i] mod 2=0 then t:=t+a[i];
end;
write(t);
readln;
end.
1Viết chương trình nhập vào số nguyên dương N. Tính tổng các số là bội 3 và 5. In kết quả ra màn hình. 2. Viết chương trình tính tổng S=1+13+15+1N+...+ cho đến khi 1N
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long i,n,x,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%15==0) t=t+x;
}
cout<<t;
return 0;
}
Viết chương trình nhập vào 1 dãy số nguyên dương có n phần tử (n là số nguyên dương nhập từ ban phím), xuất dãy số ra màn hình. Cho biết dãy số có bao nhiêu số chính phương. Số chính phương là số khi ta rút căn bậc 2 có kết quả là số nguyên. Ví dụ như số 4, 9, 16, 25, 36,.... Sắp xếp dãy số tăng dần. Xuất dãy số sau khi sắp xếp. Lưu ý: Các chức năng của chương trình đều được thực hiện bằng hàm. Ví dụ như chức năng nhập, xuất, kiểm tra chính phương, ...
bạn hỏi khó thế, đây mới là phần cho lớp 8 thôi mà
a, Viết chương trình pascal nhập vào một dãy số nguyên n từ bàn phím b, in dãy vừa nhập ra màn hình. c, đếm xem bao nhiêu số dương. d, in kết quả số dương ra màn hình.
Program HOC24;
var a: array[1..32000] of integer;
i,n,d: integer;
begin
write('Nhap N: ');
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Day vua nhap la: ');
for i:=1 to n do write(a[i],' '); writeln;
d:=0;
for i:=1 to n do if a[i]>0 then d:=d+1;
write('Co ',d,' so duong');
readln
end.
Viết một chương trình nhập n nguyên dương và n số nguyên a1, a2,…,an. a/ Tính tổng các số chẵn của dãy (In kết quả trên một dòng) b/ In các số của dãy nằm ở vị trí chẵn (2,4, 6…) ra màn hình (trên 1 dòng ),
Viết chương trình thực hiện các công việc sau: a) Nhập vào một dãy gồm N số nguyên ( N > 50) b) Hãy in ra màn hình dãy số vừa nhập c) Nhập vào một số nguyên x bất kỳ. In ra các số chia hết cho x
N = int(input("Nhập số lượng phần tử của dãy N (>50): "))
while N <= 50:
N = int(input("Nhập lại số lượng phần tử của dãy N (>50): "))
# Nhập vào dãy số
danh_sach = []
for i in range(N):
danh_sach.append(int(input("Nhập số thứ %d: " % (i+1))))
# In ra dãy số vừa nhập
print("Dãy số vừa nhập:")
for i in danh_sach:
print(i, end=' ')
# Nhập vào số nguyên x
x = int(input("nNhập vào số nguyên x: "))
# In ra các số chia hết cho x
print("Các số chia hết cho x là:")
for i in danh_sach:
if i % x == 0:
print(i, end=' ')