Thursday, October 23, 2014

How to divide two numbers using C and java

USING C

#include<stdio.h>
#include<conio.h>
int main()
{
   int x,y,z;
   x=6;
   y=6;
   z=x/y;
   printf(" the result is: %d ", z);
// %d is use of integer type variables//
   return 0;
}

USING JAVA

public static void main(String[] args)
{
  int firstvalue = 6;
  int secondvalue = 6;
  int result = firstvalue / secondvalue ;
  System.out.println("the result is: " + result);
}

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

in both  java and c the output will be

the result is: 1


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

IF WE WANT THE USER TO INPUT THE NUMBERS:

USING C

#include<stdio.h>
#include<conio.h>
int main()
{
   int x,y,z;
   printf("enter the first value:");
   scanf("%d", &x);
   printf("Enter the second value:");
   scanf("%d", &y);
   z=x/y;
   printf(" the result 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;
  int secondvalue;
  System.out.print("Enter the first value:");
  firstvalue= sc.nextInt();
  System.out.print("Enter the Second value:");
  secondvalue=sc.nextInt();
  int result = firstvalue / secondvalue ;
  System.out.println("the result of  is:" + result);



 }



}

0 comments:

Post a Comment