Sunday, October 26, 2014

How to find the Simple interest using C and java

USING C

#include<stdio.h>
#include<conio.h>
int main()
{
   int principal,rate,timeperiod,simpleinerest;
   principal=1000;
   rate=3;
  timeperiod=4;
   simpleinterest=(principal*rate*timeperiod)/100;
   printf(" the simple interest is: %d ", simpleinterest);
// %d is use of integer type variables//
   return 0;
}

USING JAVA

public static void main(String[] args)
{
  int principal = 1000;
  int rate = 3;
  int timeperiod=4
  int simpleinterest = (principal * rate * timeperiod)/100 ;
  System.out.println("the simple interest is: " + simpleinterest);
}

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

in both  java and c the output will be

the result is: 120


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

IF WE WANT THE USER TO INPUT THE NUMBERS:

USING C

#include<stdio.h>
#include<conio.h>
int main()
{
   int w,y;
   float x,z;
   printf("enter the principal money:");
   scanf("%d", &w);
   printf("Enter the rate:");
   scanf("%d", &x);
  printf("Enter the time period:");
  scanf("%d",&y);
   z=(w*x*y)/100;
   printf(" the simple interest 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;
  float thirdvalue;
  System.out.print("Enter the principal money:");
  firstvalue= sc.nextInt();
  System.out.print("Enter the time period:");
  secondvalue=sc.nextInt();
  System.out.print("Enter the rate:");
  thirdvalue=sc.nextInt();
  float result = (firstvalue * secondvalue * thirdvalue)/100 ;
  System.out.println("the simple intereste is:" + result);



 }



}

0 comments:

Post a Comment