accept a number and print its square if it's even other wise print its cube
please answer karna
Answers
Answered by
0
Answer:
#include<stdio>
using namespace std;
main()
{
int n;
cout<<"Enter a number\n";
cin>>n;
if(n%2==0)
{
cout<<"Square is = "<<n*n;
}
else
{
cout<<"Cube is = "<<n*n*n;
}
}
Answered by
1
Question:-
WAP to accept a number and print it's square if it is even otherwise print it's cube.
Program:-
import java.util.*;
class Program
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
if(n%2==1)
n*=n*n;
else
n*=n;
System.out.println("Result is: "+n);
}
}
Similar questions
Social Sciences,
3 months ago
Art,
3 months ago
Math,
3 months ago
Social Sciences,
7 months ago
Social Sciences,
1 year ago