Friday, January 6, 2012

program fungsi dan relasi

import java.io.*;
class fungsi
{
public static void main(String[] args) throws Exception
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
int n=0;
int k=0;
System.out.print("masukan banyak relasi:");
int x=Integer.parseInt(input.readLine());
int dmn []=new int[x];
int range []=new int[x];
for(int i=0;i
{
System.out.print("masukan domain ke-"+(i+1)+": ");
dmn[i]=Integer.parseInt(input.readLine());
System.out.print("masukan range ke-"+(i+1)+": ");
range[i]=Integer.parseInt(input.readLine());

}
System.out.print("domain={");
for(int i=0;i
{
System.out.print(dmn[i]);
if(i!=x-1)
System.out.print(",");

}
System.out.println("}");



System.out.print("range={");
for(int i=0;i
{
System.out.print(range[i]);
if(i!=x-1)
System.out.print(",");
}
System.out.println("}");
int i=0;
while(i
{

if (dmn[i]==dmn[i+1])
{

n=n+1;
}
if (range[i]==range[i+1])
{
k=k+1;
}
i=i+1;
}
System.out.println("fugsinya:");
for(i=0;i
{
System.out.println("("+dmn[i]+","+range[i]+")");
}
if (n!=0)
{
System.out.println("relasi tetapi bukan fungsi");
}
else
{
System.out.println("relasi dan juga fungsi");
if (k!=0)
{
System.out.println("fungsi tetapi bukan satu-satu");
System.out.println("fungsi onto");
}
else
{
System.out.println("fungsi satu-satu");
}
}


}
}





hasil dari program tersebut adalah seperti berikut :

1 comment:

  1. Gan koq bnyak tanda merahnya.. tolong di bantu gan buat tugas

    ReplyDelete