Question

In: Computer Science

main() gets user input for size and elements of arr[]. . Check each element for negative,...

main() gets user input for size and elements of arr[].
. Check each element for negative, positive and zero and create neg[], pos[] and zer[] accordingly in main() only.

Solutions

Expert Solution

C program :-

#include<stdio.h>

int main() {
int size;
printf("\nEnter the size of array :");
scanf("%d",&size);
  
int arr[size];
  
int pos[size];
int p_count=0;
  
int neg[size];
int n_count=0;
  
int zer[size];
int z_count=0;
  
for(int i=0; i<size; i++){
printf("\nenter an integer :");
scanf("%d",&arr[i]);
}
  
for(int i=0; i<size; i++){
if(arr[i]>0){
pos[p_count]=arr[i];
p_count++;
}
else if(arr[i]<0){
neg[n_count]=arr[i];
n_count++;
}
else{
zer[z_count]=arr[i];
z_count++;
}
}
  
printf("\n\nThe positive array :");
for(int i=0; i<p_count; i++){
printf("\nPositive element: %d",pos[i]);
}
  
printf("\n\nThe negative array :");
for(int i=0; i<n_count; i++){
printf("\nNegative element: %d",neg[i]);
}
  
printf("\n\nThe Zero array :");
for(int i=0; i<z_count; i++){
printf("\nZero element: %d",zer[i]);
}
}

Output:-


Related Solutions

Input: An array of non-negative integers, where each element in the array represents your maximum jump...
Input: An array of non-negative integers, where each element in the array represents your maximum jump length at that position. Output: A boolean value if you are able to reach the last index starting if you start at the first spot in the array. [Please write a recursion function!] Example 1: Input: [2,4,1,2,4,1] Output: True (Ex. 0 to 1 to 5 or 0 to 2 to 3 to 5) Example 2: Input: [3,2,1,0,4] Output: false (You will always arrive at,...
Create a project that gets input from the user. ( Name the project main.cpp) Ask the...
Create a project that gets input from the user. ( Name the project main.cpp) Ask the user for a value for each side of the triangle. Comment your code throughout. Include your name in the comments. Submit the plan-Psuedo code (include Flowchart, IPO Chart) and the desk check with each submission of your code. Submit the plan as a pdf. Snips of your output is not a plan. Save the plan and desk check as a pdf Name the code...
.......Subject Java..... main() main() will ask the user for input and then call functions to do...
.......Subject Java..... main() main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out. First function Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main(). Second function Create another function named computeBill that receives 2 parameters. It will receive the...
In main, create two FracList objects, ask the user how many elements to allocate for each...
In main, create two FracList objects, ask the user how many elements to allocate for each list, read as many Fraction objects from the keyboard as specified by the user into each (using >> operator). Sort both lists using the sort member function and display them; and then search for a value read from the user in both lists and print the index of the first occurrence or that it could not be found in either list. Swap the two...
Consider the element uniqueness problem: check whether all the elements in a given array of n...
Consider the element uniqueness problem: check whether all the elements in a given array of n elements are distinct answer in pseudo code places
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and...
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and a negative integer validates the inputs using a loop and then calls the METHOD from Question 3 and prints the result. The MAIN should have two variables (appropriately typed), get the input from the user and store them in the variables after validating them, then call the method from question 3 (sending parameters, if necessary) and print the returned value with an appropriate descriptive...
Write a function called main which gets a single number, furlongs, from the user and converts...
Write a function called main which gets a single number, furlongs, from the user and converts that to meters and prints out the converted result. The math you need to know is that there are 201.16800 meters in a furlong. your results should yield something like these test cases. >>> main() How many furlongs? 10 your 10 furlongs are 2011.68 Meters >>> main() How many furlongs? 24 your 24 furlongs are 4828.032 Meters
Discuss the four elements of negligence, and illustrate each element with an example.
Discuss the four elements of negligence, and illustrate each element with an example.
Discuss the essential elements of an enforceable contract and the significance of each element. Describe a...
Discuss the essential elements of an enforceable contract and the significance of each element. Describe a contract, possibly one in which you were a party, were involved, or of which you have personal knowledge, indicating whether the contract was express, implied, written or oral, and whether it was it breached or disputed. Did it contain the essential elements of enforceability? Did you learn anything from this experience, and if so, what would you do differently in entering into future contracts?
Briefly define each of the three elements of the fraud triangle and the fourth element of...
Briefly define each of the three elements of the fraud triangle and the fourth element of the fraud diamond.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT