Computer Science, asked by kaurjaskirat14189, 3 months ago

accept a number and print its square if it's even other wise print its cube


please answer karna​

Answers

Answered by vijayghore
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 anindyaadhikari13
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