Saturday, October 25, 2014

How to find the area of a square using C and java

USING C

#include<stdio.h>
#include<conio.h>
int main()
{
   int side,area;
   side=4;
   area=side*side;
   printf(" the area of the square is: %d ", area);
// %d is use of integer type variables//
   return 0;
}

USING JAVA

public static void main(String[] args)
{
  int side = 4;
  int area = side * side ;
  System.out.println("the area of the square is: " + area);
}

..........................................................................................................

in both  java and c the output will be

the result is: 16


...........................................................................................................

IF WE WANT THE USER TO INPUT THE NUMBERS:

USING C

#include<stdio.h>
#include<conio.h>
int main()
{
   int x,z;
   printf("enter the side:");
   scanf("%d", &x);
   z=x*x;
   printf(" the area of the square is: %d ", z);
// %d is use of integer type variables//
   return 0;
}

USING JAVA

import java.util.Scanner;
{
 static Scanner sc= new Scanner(System.in);
        public static void main(String[] args)
       {
  int firstvalue;
  System.out.print("Enter the side:");
  firstvalue= sc.nextInt();
  int result = firstvalue * firstvalue ;
  System.out.println("the area of the square is:" + result);



 }



}

0 comments:

Post a Comment