1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
maksim [4K]
3 years ago
6

Write a program to define a variable size array, ask the user to enter the size of array and its elements. Then search whether a

n element (x) exists in the array or not and print the indexes where it found (if it exists in more the one index).
Computers and Technology
1 answer:
Hunter-Best [27]3 years ago
8 0

Answer:

The program to this question can be given as:

Program:

//header file

#include <stdio.h>  

void search(int n)   //define function.

{

int a[n],find,i;  //variable declaration

printf("Enter elements of array :\n"); //message

for (i = 0; i <n; i++) //loop

{

scanf("%d", &a[i]); //input array elements

}

printf("Enter a number to search: ");

scanf("%d", &find); //input number for search

for (i = 0; i< n; i++) //search number.

{

if (a[i] == find) //if element is found in array

{

printf("%d is present at location %d.\n",find,i+1); //print location.

}

}

}

int main() //main method

{

int n; //variable declaration

printf("Enter size of array: "); //message

scanf("%d", &n); //input sizeof array.

search(n);  //calling function.

return 0;

}

Output:

Enter size of array: 6

Enter elements of array :

4

2

1

4

2

4

Enter a number to search: 4

4 is present at location 1.

4 is present at location 4.

4 is present at location 6.

Explanation:

In the above C language program firstly we define the header file that is stdio.h this header file is used to take stander input output from the user.

Then we define the main function. In this function, we declare a variable that is search, n, and i. In this, we also declare an array variable that is a[].

After inserting all array elements we take a number from the user to search number that is present in the array or not.

For this process, we define a loop. In this loop, we define a conditional statement in this if block we check elements of the array equal to search variable if this condition is true so it will print the position of number that is found in the array.  

You might be interested in
Convert 128 GB into KB​
goblinko [34]

Answer:

1,073,741,274  KB

Explanation:

Use an unit convertor or an calculator.

8 0
4 years ago
Read 2 more answers
A cyberbully is someone who invades another person’s privacy by
e-lub [12.9K]
Insulting or harassing them over the Internet
8 0
4 years ago
Read 2 more answers
What did creator Markus “Notch" Persson initially call his game
Veronika [31]

Answer:

Cave Game

Explanation:

Its initial Name was to be game cave in the developer phase and later changed to minecraft order of the stone and later changed to minecraft

7 0
3 years ago
Read 2 more answers
A startup disk cannot be detected when booting a computer. The disk's pressence is reported by the system firmware, But Windows
olasank [31]

Answer:

Bootrec.exe

Explanation:

The process of turning on a computer system is called booting. When a computer system boots, it runs the post test and loads into memory, the information or program needed to run the operating system, and then locates the operating system from the boot manager record in the disk partitions. When the disk is failed to be recorded, or the boot manager or sector is corrupt or lost, the bootrec.exe command is used in the command prompt to correct these problems.

8 0
3 years ago
Write a pyhton program to calculate area of a circle?
marta [7]

Answer:

The code to calculate the area of a circle is:

from math import pi

def circleArea(radius):

 if radius > 0:

   return pi * (radius ** 2)

 else:

   return None

if __name__ == '__main__':

 radius = 5

 print("Radius: {} Area: {}".format(radius,circleArea(radius)))

Explanation:

A detailed explanation of each line of code is given below.

#Define the number pi used to calculate the area

from math import pi

#We define a function that calculates the area of a circle

def circleArea(radius):

#Check if the radius is valid ( radius > 0) since there aren´t negative radius

 if radius > 0:

#Compute the area formula for a circle \pi * radius^{2}

   return pi * (radius ** 2)

 else:

#Return None if the radius is invalid

   return None

#Run the function we´ve defined

if __name__ == '__main__':

#Define a radius

 radius = 5

#Call the function and parse the radius through it, then print the result

 print("Radius: {} Area: {}".format(radius,circleArea(radius)))

8 0
3 years ago
Other questions:
  • A windows computer is shared between several users, each with his own local user account. Each user has his own dedicated, uniqu
    9·1 answer
  • Television broadcasts were originally delivered by using which technology
    14·1 answer
  • Describe the six clauses in the syntax of an SQL retrieval query. Show what type of constructs can be specified in each of the s
    14·1 answer
  • the header, in an academic report, typically contains the author’s name and the current page number true or false
    6·1 answer
  • How can I logout and log in?
    10·1 answer
  • A wireless networking technician has completed a survey of a wireless network and documented the detected signal strengths in va
    6·1 answer
  • Give atleast 10 examples of wearable technologies and its functions​
    10·1 answer
  • Which function works best when you need to remove an element at a specific index in a list?
    5·2 answers
  • 3. Coaxial/telephone cable sends<br> during the data transmission<br> signal
    9·1 answer
  • How many parts make up a web address? One To Three​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!