#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int count =0;
int sum = 0;
int positivecount = 0;
int negativecount = 0;
double average;
cout <<"Enter any integer or enter 0 to exit ::";
cin >> count;
while(count != 0)
{
sum += count;
average = sum / static_cast<double>(count);
count++;
if(count < 0)
{
negativecount++;
}
if (count > 0)
{
positivecount++;
}
cout <<"Enter any integer or enter 0 to exit ::";
cin >> count;
}
cout <<"the average of the numbers is " << average <<"\n";
cout <<"There are " << negativecount <<" negative numbers\n";
cout <<"There are " << positivecount<<" positive numbers\n";
system("pause");
return 0;
}
by rijaalu
//to count no. of +ve,-ve and 0s
#include
main()
{
int a[100],p=0,n=0,z=0,m,i;
printf("enter the nth no:\n");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
printf("enter %d\n",i);
scanf("%d",&a[i]);
}
for(i=1;i<=m;i++)
{
if(a[i]==0)
z++;
else if(a[i]>0)
p++;
else
n++;
}
printf("positive=%d \n Negative= %d \n Zeroes= %d \n",p,n,z);
}
So, I'm guessing you need to assume that you need to assign enough space in the array so that you can have a logical number of whatever you are storing. Use common since on this one; you wont need to allocate a 2000 index array when asking how many numbers need to be read in. So you can just use the assigned array spaces and forget about the rest. Here is an example that read in the data and does a little something different but you can change the display scores method to do what you need. Hope this helps!
import java.util.Scanner;
public class Exercise06_04
{
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
double[] givenScores = new double[10];
double sum = 0;
int count = 0;
while (count <= 10) {
System.out.print("Enter a new score: ");
double givenScore = input.nextDouble();
if (givenScore <= 0){
break;
}
else{
givenScores[count] = givenScore;
sum += givenScores[count];
count++;
}
}
double average = sum/count;
displayScores(givenScores, average, count);
}
public static void displayScores(double[] givenScores, double average, int count) {
int aboveCount = 0, belowCount = 0;
for (int i = 0; i < count; i++) {
if (givenScores[i] >= average)
aboveCount++;
else
belowCount++;
}
System.out.println("Average is " + average);
System.out.println("Number of scores above or equal to the average " + aboveCount);
System.out.println("Number of scores below the average " + belowCount);
}
}
#include<stdio.h> int main() { int num; do { scanf ("Enter a number (0 to exit): %d", num); if (num>0) printf ("The number is positive.\n"); else if (num<0) printf ("The number is negative.\n"); else printf ("The number is zero, neither positive nor negative\n"); } while (num); return 0; }
Accept 5 numbers in an array and display it.
18
By subtracting any two of the numbers A-B , if the output number is negative , B IS GREAT and if its positive A is great
ALGORITHM SAMPLE i = 0 REPEAT OUTPUT ("Enter a number: ") INPUT (number[i]) i ++ UNTIL (number[i] 0) THEN counter++ sum = sum + number[i] END IF END FOR DISPLAY (counter) DISPLAY (sum / counter) END SAMPLE
Negative number and positive numbers are all numbers. Negative numbers are just positive numbers multiplied by -1.
Negative * positive = negative Positive * positive = positive Negative * negative = positive
Negative because product of 47 negative numbers is negative and product of three positive number is Positive , so negative*positive = Negative.
(The product of 33 negative numbers) x (2 positive numbers) = (negative sign) x (positive sign) = negative sign
negative
positive
Positive x Positive =Positive Positive x Negative= Negative Negative x Positive= Negative Negative x Negative =Positive
'cuz
It is positive. Any product of an even number of negative numbers will be positive, regardless of how many positive numbers you have. Similarly any product of an odd number of negative numbers will be negative, regardless of how many positive numbers you have.
Positive numbers, on your door. Negative in your freezer.
yes integers are all numbers negative and positive
Positive numbers are larger than negative ones.