Easy
Easy
21
1
12
12
12
01
S0
S0
S0
S
BB
BB
BB
BB
Name: GUTHULA BHARGAVCHANDRA . Scan to verify results
23
23
23
23
Email: [email protected]
Roll no: 23BBS0121
Phone: 9999999999
Branch: MUKKU NISANTH KARTHEEK_DSA
Department: admin
Batch: VL2024250505225
Degree: admin
21
1
12
12
12
01
S0
S0
BS
BB
BB
BB
B
23
23
23
23
VIT V_Scope_DAA_Week 3_COD_Easy
Attempt : 1
Total Mark : 20
Marks Obtained : 20
Section 1 : Coding
1. Problem Statement
1
21
1
12
12
12
01
S0
S0
S
BB
BB
BB
find prime numbers within a given range [L, R] using the brute force BB
23
23
23
23
technique.
Answer
#include<iostream>
using namespace std;
int main()
{
1
21
int l;
12
12
12
01
cin>>l;
S0
S0
S0
S
BB
BB
BB
BB
int r;
23
23
23
23
cin>>r;
1
21
1
12
12
12
int flag;
01
S0
S0
S0
S
for(int i=l;i<=r;i++)
BB
BB
BB
BB
{
23
23
23
23
flag=0;
for(int j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0 && i!=1)
21
1
12
12
12
{
01
S0
S0
S0
BS
cout<<i<<" ";
BB
BB
BB
B
}
23
23
23
23
}
return 0;
}
2. Problem Statement
You are tasked with finding the maximum subarray sum in a given array
1
21
1
12
12
12
01
S0
S0
S
BB
BB
BB
BB
array.
23
23
23
23
Answer
#include<iostream>
#include<climits>
using namespace std;
int main()
{
1
21
12
12
12
01
int n,sum,maxi=INT_MIN;
S0
S0
S0
cin>>n;
BB
BB
BB
BB
23
23
23
23
int arr[n];
1
21
1
12
12
12
for(int i=0;i<n;i++)
01
S0
S0
S0
S
{
BB
BB
BB
BB
cin>>arr[i];
23
23
23
23
}
for(int i=0;i<n;i++)
{
sum=0;
for(int j=i;j<n;j++)
{
sum+=arr[j];
maxi=max(sum,maxi);
}
21
1
12
12
12
}
01
S0
S0
S0
BS
cout<<maxi;
BB
BB
BB
B
return 0;
23
23
23
23
}
21
1
12
12
12
01
S0
S0
S0
S
BB
BB
BB
BB
23
23
23
23
1
21
12
12
12
01
S0
S0
S0
S
BB
BB
BB
BB
23
23
23
23