Uri 1173 Solution || Beecrowd 1173 – Array fill I solution in C,CPP

Uri 1173 Solution || Beecrowd 1173 – Array fill I solution

Question link:

Beecrowd 1173 – Array fill I solution in C

#include <stdio.h>

int main() {
int N[10],i,d;

scanf("%d",&d);

for(i=0;i<10;i++){
N[i]=d;
printf("N[%d] = %d\n",i,d);
d*=2;
}

return 0;
}

Beecrowd 1173 – Array fill I solution in C++

#include <iostream>
using namespace std;

int main() {
    int N[10], i, d;

    cin >> d;

    for(i = 0; i < 10; i++) {
        N[i] = d;
        cout << "N[" << i << "] = " << d << endl;
        d *= 2;
    }

    return 0;
}

Beecrowd 1173 – Array fill I solution in Python

# Python version of the C code

# Taking input
d = int(input())

# Initialize an empty list
N = []

# Loop to populate the list and print values
for i in range(10):
    N.append(d)
    print(f'N[{i}] = {d}')
    d *= 2

1. Input Handling:By means of the input() function, this code gets an integer d as input from users; int() makes it an integer.

2. List Initialization:A blank list named N has been initialized to hold all the values that will be generated through the loop.

3. Loop Logic:There is a loop that runs for ten times during which the current value of d will be added to the list N and also output the index i and its value d in a format N[i]=d.

4. Value Doubling: For every pass on through the aforementioned steps, the value of d remains multiplied by 2 repeating itself for ten times in total.

Beecrowd 1172 – Array Replacement I solution in C/Cpp

1 thought on “Uri 1173 Solution || Beecrowd 1173 – Array fill I solution in C,CPP”

Leave a Comment