Showing posts with label c. Show all posts
Showing posts with label c. Show all posts

Saturday, 20 November 2021

Q4_even_odd_array

even_odd

4. Java Program to print the elements of an array present on even position and odd position

In this program, we need to kwon the given array element indexing that is how to indetife to odd position and even positon element which is ? . This can be accomplished by looping through the array and store the elements of the array into the odd and even element array at the corresponding position.

Original array

23 4 31 8 5

Even position

23 31 5

odd position

4 8

Algorithm

  • 1.START
  • 2.INITIALIZE arr1[] ={1, 2, 3, 4, 5}
  • 3.start for loop
  • 4.if(i%2==0) is even position
  • 5.if(i%2!=0) is odd position
  • 4.display array

Program

class Q4_odd_even {

public static void main(String[] args)

//declare array

int arr[]={23, 4 ,31, 8, 5};

System.out.println("original array is");

for(int i=0;i< arr.length;i++)

{

System.out.print(arr[i] + " ");

}

//display even position of array

System.out.println("even postiton of array element \n");

for(int i=0;i< arr.length;i++)

{

if(i%2==0)

{

System.out.print(arr[i] + " ");

}

}

//display odd position element of array

System.out.println("odd postiton of array element \n");

for(int i=0;i< arr.length;i++)

{

if(i%2!=0)

{

System.out.print(arr[i] + " ");

}

}

output

original array is:

23 4 31 8 5

even position of array is:

23 31 5

odd position of array is:

4 8

Next Topic

Monday, 8 November 2021

c_short_answer

Document

C Programming Interview Questions

C is a mid-level and procedural programming language. The Procedural programming language is also known as the structured programming language

is a technique in which large programs are broken down into smaller modules, and each module uses structured code. This technique minimizes error and misinterpretation

C is known as a mother language because most of the compilers and JVMs are written in C language.

Most of the languages which are developed after C language has borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new core concepts like arrays, functions, file handling which are used in these languages.

Simple: C is a simple language because it follows the structured approach, i.e., a program is broken into parts

Fast Speed: C language is very fast as it uses a powerful set of data types and operators.

Memory Management: C provides an inbuilt memory function that saves the memory and improves the efficiency of our program.

Structured: C is a structured language as the C program is broken into parts.

Local variable Global variable
A variable which is declared inside function or block is known as a local variable. A variable which is declared outside function or block is known as a global variable.
The scope of a variable is available within a function in which they are declared. The scope of a variable is available throughout the program.
Variables are stored in a stack unless specified. The compiler decides the storage location of a variable.

1.C functions are used to avoid the rewriting the same code again and again in our program.

2.C functions can be called any number of times from any place of our program.

3.C functions provide the reusability concept, i.e., it breaks the big task into smaller tasks so that it makes the C program more understandable.

When a function calls itself, and this process is known as recursion. The function that calls itself is known as a recursive function.

A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast.

Whenever a variable is declared inside a program, then the system allocates some memory to a variable.

The memory contains some address number. The variables that hold this address number is known as the pointer variable.

Accessing array elements: Pointers are used in traversing through an array of integers and strings. The string is an array of characters which is terminated by a null character '\0'.

Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct different data structures like tree, graph, linked list, etc.

Call by Reference: The pointers are used to pass a reference of a variable to other function.

In case of static memory allocation, memory is allocated at compile time, and memory can't be increased while executing the program. It is used in the array.

The lifetime of a variable in static memory is the lifetime of a program. The static memory is allocated using static keyword. The static memory is implemented using stacks or heap.

The pointer is required to access the variable present in the static memory. In static memory, more memory space is required to store the variable.

In case of dynamic memory allocation, memory is allocated at runtime and memory can be increased while executing the program. It is used in the linked list.

An allocation or deallocation of memory is done at the execution time of a program. No dynamic pointers are required to access the memory. The dynamic memory is implemented using data segments. Less memory space is required to store the variable.

How do you select data from a table in SQL?

Create Table How do you select data a table in SQL? The SELECT statement is used to se...