1. WAP to print all the negative intergers from 0 to -50
Answers
Answer:
Explanation:
WAP to print all the negative intergers from 0 to -50
import java.util.*;
class GFG
{
static void printPairs(int arr[], int n)
{
boolean pair_exists = false;
Arrays.sort(arr);
for (int i = 0; i < n; i++)
{
if (arr[i] < 0)
{
if (java.util.Arrays.binarySearch(arr, -arr[i])!=-1)
{
System.out.println(arr[i] + ", " + -arr[i] );
pair_exists = true;
}
}
else
break;
}
if (pair_exists == false)
System.out.println("No such pair exists");
}
Answer:
In C++,
Using for loop:
#include <iostream>
using namespace std;
int main() {
for (int i = -50; i < 0; i++) {
cout << i << " ";
}
}
Using while loop:
#include <iostream>
using namespace std;
int main() {
int a = -50;
while (a < 0) {
cout << a << " ";
a++;
}
}
Explanation:
Run a loop from -50 to 0