0% found this document useful (0 votes)
5 views

Easy

The document contains the academic details and programming assignments of a student named Guthula Bhargavchandra from VIT Vellore. It includes two coding problems: one for finding prime numbers within a given range and another for calculating the maximum subarray sum, both of which were solved correctly. The student received full marks for both assignments.

Uploaded by

gbhargavchandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Easy

The document contains the academic details and programming assignments of a student named Guthula Bhargavchandra from VIT Vellore. It includes two coding problems: one for finding prime numbers within a given range and another for calculating the maximum subarray sum, both of which were solved correctly. The student received full marks for both assignments.

Uploaded by

gbhargavchandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

VIT - Vellore

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

CBS3003_Design and Analysis of Algorithms_VL2024250505225


S0

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

Imagine you're organizing a math competition where participants need to


S0

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.

Write a program to identify and display these prime numbers as a list.

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;
}

Status : Correct Marks : 10/10

2. Problem Statement

You are tasked with finding the maximum subarray sum in a given array
1

21

1
12

12

12
01

using the brute force technique. A subarray is a contiguous segment of the


S0

S0

S0
S
BB

BB

BB

BB
array.
23

23

23

23

Your goal is to implement a program that takes an array of integers as


input and finds the maximum sum of a subarray within that array.

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
}

Status : Correct Marks : 10/10


1

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

You might also like