मराठी

Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.int a = new int (5);for (int i = 0; i < = 5; i++) a [i] = i;

Advertisements
Advertisements

प्रश्न

Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.
int a = new int (5);
for (int i = 0; i < = 5; i++) a [i] = i;

थोडक्यात उत्तर
Advertisements

उत्तर

The errors are follows:

  1. In the first line, the variable must be a[ ] and 5 must be inside square brackets as new int[5].
  2. In the second line, the relational operator must be < instead of <=.

The correct statements are:

int a[] = new int[5]; 
for (int i = 0; i < 5; i++) a[i] = i;
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 3: Arrays (Single Dimensional and Double Dimensional) - Review Insight [पृष्ठ २३७]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
पाठ 3 Arrays (Single Dimensional and Double Dimensional)
Review Insight | Q 10. | पृष्ठ २३७

संबंधित प्रश्‍न

What is the difference between the linear search and the binary search technique?


Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique. 


Name the following :
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.


Differentiate between searching and sorting.


If int x [ ] = { 4, 3,7, 8, 9,10}; what are the values of p and q ?

(i) p = x.length
(ii) q = x[2] + x[5] * x[1]


Write a program to input forty words in an array. Arrange these words in descending order of alphabets, using selection sort technique. Print the sorted array.


Using the switch statement, write a menu driven program to:
(i) To find and display all the factors of a number input by the user (including 1 and excluding number itself).

Example:
Sample Input: n=15
Sample Output: 1, 3, 5.
(ii) To find and display the factorial of a number input by the user (the factorial of a non-negative integer n, denoted by n\ is the product of all integers less than or equal to n.
Example:
Sample Input: n=5
Sample Output: 5! = 1×2×3×4×5 = 120.
For an incorrect choice, an appropriate error message should be displayed.


Consider the given array and answer the question given below:

int x[ ] {4; 7,9,66,72,0,16);

What is the length of the array?


Consider the given array and answer the question given below:

int x[ ] {4; 7,9,66,72,0,16);

What is the value in x[4]?


Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending order. Display the sorted array and original array.


Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×