Skip to main content

ads1

Class 10th chapter :- 15 ARRAYS

  Arrays


It is a collection of elements having same data type, It is a fixed-size sequential collection of elements. An array element occupies contiguous memory locations.

C supports a special kind of data type called an array.

The element of an array is accessed by an index number. The index number contained within square brackets is also known as subscript.

Types of Arrays The arrays in C language can be classified in to following two categories :

(1) Single or One dimensional array
(2) Multidimensional array

The single dimensional array may have one row or one column while multidimensional array has one or more rows and one or more columns. The number of rows and columns are specified by user as per the program requirement.  Declaration of Single Dimensional Array

To declare an array in C language, we specify the type of data which we want to store in the elements and the number of elements to be stored in an array as follows:
datatype
arrayname ( size );
datatype: It specify the type of elements that an array stores. If we want to store characters in an array then type of an array is 'char'. In the same way to store integers, type of an array is 'int'. The datatype can be any valid C language data type.

arrayname: This is the name given to an array variable by the programmer. It can be any string but it is usually suggested that some meaningful name should be given to an array. The array name should be in context with what is being stored in that array in a program.

size: The value of size indicates the number of elements the array can stores. The size must be an integer constant greater than zero.

(1) What happens if a C program tries to access a value from an array element whose subscript exceeds the size of array ?
(a) The element will be set to 0.
(b) The compiler would report an error.
(c) The program may crash or gives garbage data.
(d) The array size increases automatically.

(2) What will be the output of following program segment?
int num[5] = {1, 2, 3, 4, 5};
int i, j;
i = num[1];
j = num[2];
printf("%d, %d, %d", i, j, num[0]);

 (a) 1, 2, 3 

(b) 2, 3, 1
(c) 1, 2, 0
(d) 3,4,5

(3) What will be the output of following program segment ?
int num[5] = {1, 2, 3};
printf("%d, %d", num[0], num[3]);
(a) 1, 2
(b) 1, 0
(c) 1, 3
(d) 2,3

ads2

Popular posts from this blog

11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following:

    11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95% Static Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     if(basic <=10000)     {         da = basic * 0.8;         hra = basic *0.2;     }              else if(basic <=20000)     {         da = basic * 0.9;         hra = basic *0.25;     }     else     {         da = basic * 0.95;         hra = basic * 0.3;     }     gross = basic + da + hra;     System.out.println("The Gross Salary is :-"+gross);     } } Output :-  Dynamic Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     Scanner in = new Scanner(System.in);     System.out.println("Enter the Basic Salary

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise or class wise.

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise  or class wise. Solution :-   # x-axis is shows the subject and y -axis # shows the markers in each subject # import pandas and matplotlib  import pandas as pd  import matplotlib.pyplot as plt # Simple Line Chart with setting of Label of X and Y axis, # title for chart line and color of line  subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer'] marks =[80,75,70,78,82] # To draw line in red colour plt.plot(subject,marks,'r',marker ='*')     # To Write Title of the Line Chart plt.title('Marks Scored') # To Put Label At Y Axis plt.xlabel('SUBJECT')           # To Put Label At X Axis plt.ylabel('MARKS')             plt.show() Output :- 

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category.

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category. import pandas as pd  # initialize list of lists data = [['CAR','Maruti',1000000],['AC','Hitachi',55000],['AIRCOLLER','Bajaj',12000], ['WASHING MACHINE','LG',15000],['CAR','Ford',7000000],['AC','SAMSUNG',45000],['AIRCOLLER','Symphony',20000],['WASHING MACHINE','Wirlpool',25000]] Col=['itemcat','itemname','expenditure'] # Create the pandas DataFrame qrtsales = pd.DataFrame(data,columns=Col) # print dataframe.  print (qrtsales) qs=qrtsales.groupby('itemcat')  print('Result after Filtering Dataframe')  print(qs['itemcat','expenditure'].sum()) Output :-