Viết chương trình khởi tạo một ma trận \(A\)
K
Khách

Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.

#include <bits/stdc++.h>
using namespace std;
long long a[300][300];
int main()
{
    long long m, n;
    cin>>m>>n;
    for(int i=1; i<=m; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if((i+j)%2==0)
            {
                a[i][j]=0;
            }
            else a[i][j]=1;
        }
    }
    for(int i=1; i<=m; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<'\n';
    }
}

1 tháng 3 2024

Phía cuối cout<<'\n' em thiếu ; rồi. Với lại em nên khởi tạo ma trận bằng 1 sau đó mới thực hiện điều kiện như đề bài nha. Testcase của đề bài hơi lỗi thì phải.

8 tháng 10 2021

photography

8 tháng 10 2021

/add link /ustrscr

grammar. sotnihuynb opijqv  iurtb 9eiyb 

25 tháng 12 2019

1: tính tổng của \(S=1+\frac{1}{2^2}+\frac{1}{3^2}+\frac{1}{4^2}+...+\frac{1}{100^2}\)

uses crt;

var s:real;

i:integer;

begin

clrscr;

s:=0;

for i:=1 to 100 do

s:=s+1/(sqr(i));

writeln('tong cua day so la: ',s);

readln;

end.

2: tính tổng \(S=1+\frac{1}{3^2}+\frac{1}{5^2}+\frac{1}{7^2}+...+\frac{1}{n^2}\)

uses crt;

var s:real;

n,i:integer;

begin

clrscr;

write('n='); readln(n);

s:=0;

for i:=1 to n do

if i mod 2=1 then s:=s+1/(sqr(i));

writeln('tong cua day so la: ',s:4:2);

readln;

end.

25 tháng 12 2019

Hỏi đáp Tin họcHỏi đáp Tin học

5 tháng 3 2020

Program hotrotinhoc;

var d,n,i: byte;

a: array[1..100] of byte;

begin

write('N='); readln(n);

d:=0;

for i:=1 to n do

begin

write('a[',i,']='); readln(a[i]);

if a[i] mod 2=0 then inc(d);

end;

write('Mang vua nhap la :');

for i:=1 to n do write(a[i],' ');

writeln;

write('So phan tu chan la : ',d);

readln

end.

30 tháng 10 2017

\(\dfrac{14}{7}hay\dfrac{17}{7}?\)

30 tháng 10 2017

\(\dfrac{14}{7}\)

7 tháng 10 2020

uses crt;

var x,y,z:real;

begin

clrscr;

write('Nhap x='); readln(x);

write('Nhap y='); readln(y);

z:=abs(1-sqr(x))+abs(1-sqr(y));

writeln('Z=',z:4:2);

readln;

end.

9 tháng 10 2020

mik làm cả 2 bằng 1 ct nha

var x,y,z1,z2:real;

begin

write(' Nhap x: ');readln(x);

write(' Nhap y: ');readln(y);

z1:=abs(1-sqr(x)) + abs(1-sqr(y));

z2:=abs(1-exp(x)) + abs(1-exp(y));

writeln(' KQ b1 :' ,z1:0:1);

writeln('KQ b2: ',z2:0:1);

readln;

end.

7 tháng 4 2025

def generate_sequence(n):

"""Generates the sequence A up to the nth term."""


if n < 0:

return "Please enter a non-negative number."


sequence = [] # This list will hold our sequence


if n >= 0:

sequence.append(1) # A[0] = 1


if n >= 1:

sequence.append(3) # A[1] = 3


for i in range(2, n + 1):

# Calculate A[i] using the rule: A[i] = A[i-1] * 2 * A[i-2]

next_term = sequence[i - 1] * 2 * sequence[i - 2]

sequence.append(next_term)


return sequence


# Let's see the sequence up to the 5th term (A[0] to A[5])

result = generate_sequence(5)

print(result) # Output: [1, 3, 6, 36, 432, 31104]