हिंदी

Fill an array (type int, size n). Perform Left Circular Shift.

Advertisements
Advertisements

प्रश्न

Fill an array (type int, size n).

Perform Left Circular Shift.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class clArraysSelection 
{
    public void main() 
    {
        Scanner sc = new Scanner(System.in);
        System.out.print(" Enter the array size : ");
        int n = sc.nextInt();
        int R[] = new int[n];
        int j = 0;
        for (j = 0; j < n; j++) 
        {
           System.out.print("Enter value for cell number " + (j) + “ : ");
           R[j] = sc.nextInt();
        }
        System.out.println("/t The array is: ");
        for(j = 0; j<n;j++)
        {
           System.out.print(" " + R[j]);
        }
        //left circular shift 
        int tmp = R[O];
        for(j= 1; j<n; j++)
        {
           R[j -1] = R[j];
        }
        R[n - 1] = tmp;
        System.out.println("\n\n The array after a left circular shift : ");
        for(j = 0; j<n; j++)
        {
           System.out.print("/t " + R[j]);
        }
    }
}

Output:

The array is : 

99 22 77 44 55 11

The array after a Left Circular Shift : 22 77 44 55 11 99

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 11: Programs Overall - Arrays [पृष्ठ २५२]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 11 Programs Overall
Arrays | Q 9. | पृष्ठ २५२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×