Question

In: Electrical Engineering

A matlab program to enter N numbers and count the positive, negative and zero numbers. Then...

A matlab program to enter N numbers and count the positive, negative and zero numbers. Then print the results

Solutions

Expert Solution

The matlab program to count positve negative and zeros of the enterd no :

N=input("enter a no of elements") % asking no of elements
  
arr=zeros(1,N); %intitialzing empty arry with 1 row and n no of columns
for i=1:1:N % for loop to get the elemnts from user
k=input("enter the elements"); % asking every element in the arry
arr(i)=k; % assigning value to arry
end % ending the for loop

fprintf(" the arry is :\n"); % printing the arry
for i=1:1:N % for loop to print the elements of the arry
disp(arr(i)) % displaying arry elements
end % ending the for loop

pos=0;neg=0;zero=0; % intitalizing the positive,negative,zeros are 0

for i=1:1:N % for loop to access elements in the arry
if(arr(i)==0) % checking if the elment is 0 or not
  
zero=zero+1; % incrementing zeros if condition is true
  
elseif(arr(i)<0) % checking the element is negative or not
  
neg=neg+1; % incrementing neg if condition is true
else
pos=pos+1; % if element is not zero and negative then increments the pos
end % ending the condition
end % ending the for loop

fprintf("the total no of positive no are : %d \n",pos); % prints total no of pos no
fprintf("the total no of negative no are : %d \n",neg); % prints total no of neg no
fprintf("the total no of zeros no are : %d \n",zero); % prints total no of zeros

The ouput for the above program is :-

  


Related Solutions

Write a python program that will ask the user to enter as many positive and negative...
Write a python program that will ask the user to enter as many positive and negative numbers and this process will only stop when the last number entered is -999. Use a while loop for this purpose. Your program should compute three sums; the sum of all numbers, sum of all positive numbers, and the sum of all negative numbers and display them. It should also display the count of all numbers, count of all positive numbers, and count of...
For example, suppose you had a program to determine if a number is positive, negative or zero.
  For example, suppose you had a program to determine if a number is positive, negative or zero. Read in a number and then use the if statement to determine if the number is positive (>0) or negative (<0) or zero (==0): if (x>0)//display positive messageelse if (x<0)   //display negative messageelse//display zero message
Make a program that lets the user enter a positive or negative integer as many times...
Make a program that lets the user enter a positive or negative integer as many times as they want. java //import statement //class header //Begin class scope //Method header for main. //Begin method scope. //Declare input object for Scanner. //Declare variable called entry initialized to zero. //Declare variable called response initialized to blank space. //Prompt "Do you want to enter an integer? Y or N: " //Store value in correct variable.   //while header that tests uppercase in response //Begin scope...
For each statement select P for Positive, N for Negative, or Z for Zero charge (Neutral)....
For each statement select P for Positive, N for Negative, or Z for Zero charge (Neutral). (If the first answer is positive, the second negative, and the third neutral (zero net charge), enter PNZ. A) A negatively charged rod is brought close to a neutral isolated conductor, but it does not touch. The rod is then removed. What is the final charge of the conductor? B) A negatively charged rod is brought close to a neutral isolated conductor, but it...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
                         Positive       Negative Influenza A.       &n
                         Positive       Negative Influenza A.         360.              7 no influenza A.      6.               1110 find the probability of a subject with a positive test result given that the subject does have influenza A find the probability of selecting a subject with a negative test result given that the subject does not have influenza a
Write C program : Enter N and N pairs of positive integerpairs, convert each pair...
Write C program : Enter N and N pairs of positive integer pairs, convert each pair of positive integers into binary and add, and output the formula. Decimal to binary function prototype: int DecToBin(int integer);The range of input N is 1 <= N <= 100, and the range of positive integers input is 0 < n <= 255. The output format is %08d. If the entered N or positive integer is out of range, "Invalid input" is output. If a...
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
Write a Java program (name it InputSum) that prompts the user to enter positive integer numbers...
Write a Java program (name it InputSum) that prompts the user to enter positive integer numbers using a sentinel while loop. The program should accept integer inputs until the user enters the value -1 (negative one is the sentinel value that stops the while loop). After the user enters -1, the program should display the entered numbers followed by their sum as shown below. Notice that -1 is not part of the output. The program should ignore any other negative...
Java Program Problem // Description: Read five positive integers and average them. // Enter a negative...
Java Program Problem // Description: Read five positive integers and average them. // Enter a negative integer to end the program. import java.util.Scanner; public class Lab5 { public static void main (String args[]) {        Scanner sc;        sc = new Scanner(System.in);    final int MAX_NUMS = 5;        int num;       // variable to store the number        int sum;   // variable to store the sum        int count;    // variable to store...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT