When I make the program for this given task how do I print only non zero elements of array not the whole array and can anyone tell how to terminate if array is non zero. Sorry i am just a beginner !!
[code]
Put the code you need help with here.
Write a program in C++ to identify array in which no zero present, and print those numbers. If user input a value without zero program should terminate.
By Terminate,I mean terminate the program. On that I will be using "IF " and Else If" to terminate the program when no zero in array is entered by user. Sorry that was typo i mean elements of Array,if no zero is present in elements entered by user of Array then terminate the program.
Shawnamous (2)
By Terminate,I mean terminate the program. On that I will be using "IF " and Else If" to terminate the program when no zero in array is entered by user. Sorry that was typo i mean elements of Array,if no zero is present in elements entered by user of Array then terminate the program.
track it as you read them in.
1 2 3 4 5 6 7 8 9
main
bool quitnz{true};
for(..)
{
read in numbers[i]
quitnz &= numbers[i];
}
if(quitnz) return; //because its in main, the return quits the program cleanly. add a print to tell them why?
there is another account asking the same question in broken english. Hmm.
#include <iostream>
using namespace std ;
int main ( ) {
int n [ 5 ] ;
int y =1 ;
for ( int x = 0 ;
x < 5 ; x ++ ) {
cout << " Enter the << x << element >> n [ x ] ;
cin >>n[x];
if ( n [ x ] == 0 ) {
y==0;
break }
}
if ( y== 1 ) {
y = 0 ;
cout << " \ nElements of array are";
for ( int x = 0 ; x < 5 ; x ++ ) {
cout << n [ x ] << " , " ;
}
}
else if ( y == 0 ) {
cout <<" PROGRAM IS TERMINATED " << endl ;