write a c++ program to input a number. if number is odd and positive, print cube or else print square
Show your code.
=
We will help you make it work right.
You can use modulo or if it's too complicated, try these:
if ((n >1) << 1 == n) then even
if ((n >1) << 1 != n) then odd
if (((n >1) << 1) - n == 0) then even
if (n - ((n >1) << 1) == 1) then odd
I think the following program fulfill ur needs.....
#include<iostream.h>
#include<conio.h>
void main()
{
int val,a,b;
cout<<"Enter the number: ";
cin>>val;
a=val%2;
b=val-val;
if(a != 0 && b==0)
cout<<"Cube";
else
cout<<"Square";
getch();
}
You forgot to ask a question. What is your question about this assignment?
yes, squared
u want us to write it for u?
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
Verified answer
Show your code.
=
We will help you make it work right.
You can use modulo or if it's too complicated, try these:
if ((n >1) << 1 == n) then even
if ((n >1) << 1 != n) then odd
if (((n >1) << 1) - n == 0) then even
if (n - ((n >1) << 1) == 1) then odd
I think the following program fulfill ur needs.....
#include<iostream.h>
#include<conio.h>
void main()
{
int val,a,b;
cout<<"Enter the number: ";
cin>>val;
a=val%2;
b=val-val;
if(a != 0 && b==0)
cout<<"Cube";
else
cout<<"Square";
getch();
}
You forgot to ask a question. What is your question about this assignment?
yes, squared
u want us to write it for u?