Computer Science, asked by mamtaraina618, 9 months ago

write a program to print area of rectangle. take input from user​

Answers

Answered by purveshKolhe
32

\huge{\red{\underline{\underline{\pink{\mathfrak{Java::}}}}}}

import java.util.Scanner;

public class Main {

  public static void main(String [] args) {

     Scanner sc = new Scanner(System.in);

     int length = sc.nextInt();

     int breadth = sc.nextInt();

     System.out.println("Area of the rectangle is : " + (length * breadth));

  }

}

\huge{\red{\underline{\underline{\blue{\mathfrak{Logic::}}}}}}

  • Line 1 - Imports Scanner class for input.
  • Line 2 - Declares class Main.
  • Line 3 - Main method.
  • Line 4 - Activation of Scanner.
  • Line 5 - Gets 1st input.
  • Line 6 - Gets 2nd input.
  • Line 7 Prints the area.

\huge{\red{\underline{\underline{\pink{\mathfrak{Python::}}}}}}

length = int(input())

breadth = int(input())

print("Area of the rectangle is : " + str(length * breadth))

\huge{\red{\underline{\underline{\blue{\mathfrak{Logic::}}}}}}

  • Line 1 - Gets 1st input.
  • Line 2 - Gets 2nd input.
  • Line 3 - Prints the area.

\huge{\red{\underline{\underline{\pink{\mathfrak{C++::}}}}}}

#include <iostream>

using namespace std;

int main() {

  int length, breadth;

  cin >> length;

  cin >> breadth;

  cout << "Area of rectangle is : " << (length *  breadth);

  return 0;

}

\huge{\red{\underline{\underline{\blue{\mathfrak{Logic::}}}}}}

  • Line 1 - Includes the header file.
  • Line 2 - Declares that we are using standard namespace.
  • Line 3 - White space.
  • Line 4 - Main method.
  • Line 5 - Declaration of variables in which the input is to be taken.
  • Line 6 - Gets 1st input.
  • Line 7 - Gets 2nd input.
  • Line 8 - Prints the area.
  • Line 9 - Required at the end of every C++ program.

Hope it helps..♪

Attachments:
Similar questions