Computer Science, asked by ironsohan, 6 months ago

1. WAP to print all the negative intergers from 0 to -50​

Answers

Answered by Sd12365
1

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");  

}  

 

Answered by prasunap
0

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

Similar questions