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

Write a MATLAB script which gets a matrix as input and check the dimensions of the...
Write a MATLAB script which gets a matrix as input and check the dimensions of the input: Part A) If the input matrix is a square matrix, calculate the inverse of it and show it in the command window, otherwise, show the text “the input matrix is not invertible”. Part B) Reshape the input matrix to a row vector and assign it to Y and make a vector named X with the same length as Y then make a 2D...
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,...
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. 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, and get stuck at, index...
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...
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...
.......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 python write a program that gets a list of integers from input, and outputs non-negative...
In python write a program that gets a list of integers from input, and outputs non-negative integers in ascending order (lowest to highest). Ex: If the input is: 10 -7 4 39 -6 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space. Do not end with newline
write a program named Combinations.java that gets user input for two integers n and k, then...
write a program named Combinations.java that gets user input for two integers n and k, then computes and displays the value of n choose k using the efficient method of equation. you may assume that the user's input makes sense (i.e, n and k are non negative, and n is at least k). your code should work for any reasonably small non- negative values of n and k, including zero.
write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT