Request The User To Type Numbers, Each Time Printing Its Triple, Until The User Enters - 1
Request The User To Type Numbers, Each Time Printing Its Triple, Until The User Enters - 1
Request the user to type numbers, each time printing its triple, until
the user enters -1.
#include <iostream.h>
int main() {
for (int input; input != -1;) {
cout << "Enter a number (-1 to quit): ";
cin >> input;
if (input != -1)
cout << "Tripled: " << input * 3 <<
endl;
}
return 0;
}
2. Write a Program to find out no. of Even & Odd no. in a given Data
Series and terminate if entered value is -1.
#include <iostream.h>
int main()
int num;
while(num != -1){
if (num % 2 == 0) even_n++;
else odd_n++;
return 0;
}
3. What is the output of the following
#include <iostream.h>
int main()
if (i != 5) continue;
if (k == 3) continue;
5
00 01 02 04 10 11 12 14
4. Write a program that calculates and prints the product of the odd
integers from 1 to 100.
#include <iostream.h>
int main()
long product = 1;
{ product *= i; }
cout << "Product of the odd integers from 1 to
100 is: "
return 0;
}
5. Write a program that calculates and prints the average of several
integers. Assume the last value read is the sentinel -1
#include <iostream.h>
int main()
while ( value != -1 ) {
total += value;
++count;
if ( count != 0 )
else
return 0;