Monday, 8 April 2013

else


#include<stdio.h>
#include<windows.h>

void main()
{
char nama_subjek[10][100];
float creditHour[10000];
float gradePoint[10000];
float markah[10000];
char grade;

double sumCH=0;
double sum_CHxGP=0;
double GPA=0;

int x;
int y;

system("color 3f");

printf("Sila masukkan jumlah subjek:");
scanf("%d", &y);

for(x=1;x<=y;x++)
{
printf("Sila masukkan nama subjek, masukkan markah subjek,\n nilai credit hour dan grade point untuk subjek %d:\n",x);

printf("nama subjek:");
scanf("%s", &nama_subjek[x]);

printf("markah :");
scanf("%f", &markah[x]);

printf("credit hour :");
scanf("%f", &creditHour[x]);

if(markah[x]>=80 && markah[x]<=100)
{
gradePoint[x]=4.00;

}

else if(markah[x]>=75 && markah[x]<=79)
{

gradePoint[x]=3.67;

}
else if(markah[x]>=70 && markah[x]<=74)
{

gradePoint[x]=3.33;

}
else if(markah[x]>=65 && markah[x]<=69)
{

gradePoint[x]=3.00;

}
else if(markah[x]>=60 && markah[x]<=64)
{

gradePoint[x]=3;

}
else if(markah[x]>=55 && markah[x]<=59)
{

gradePoint[x]=2.33;

}
else if(markah[x]>=50 && markah[x]<=54)
{

gradePoint[x]=2.00;

}
else if(markah[x]>=45 && markah[x]<=49)
{

gradePoint[x]=1.67;

}
else if(markah[x]>=40 && markah[x]<=44)
{

gradePoint[x]=1.00;

}
else if(markah[x]>=0 && markah[x]<=39)
{

gradePoint[x]=0.00;

}
else
{
printf("your mark is invalid");
}
}

for(x=1;x<=y;x++)
{
sumCH=sumCH+creditHour[x];
sum_CHxGP=sum_CHxGP+ creditHour[x]*gradePoint[x];

system("cls");
printf("--------------------------------------------------------------------------------\n");
printf("\t\tNama Subjek \t Markah \t Grade Point \t Credit Hour\n");
printf("--------------------------------------------------------------------------------\n");
printf("\t\t%s \t \t%.2f \t \t%.2f\t\t%.2f" ,nama_subjek[x],markah[x],gradePoint[x],creditHour[x]);
printf("\n--------------------------------------------------------------------------------\n");
}

printf("\ntotal grade point average (GPA) anda ialah.. %.2f\n",sum_CHxGP/sumCH);

}

diagonal


#include<stdio.h>
#include<math.h>

void main()
{
float x;
float y;
double hasil;

printf("\nMasukan nilai x=");
scanf("%f",&x);

printf("\nMasukan nilai y=");
scanf("%f",&y);
   
hasil=sqrt ((x*x)+(y*y));

printf("hasil darab %f dan %f adalah %f\n",x,y,hasil);
}

circle function


#include<stdio.h>
#include<math.h>
#include<windows.h>
#define PI 3.14

void areacircle(float radius);
void circumferencecircle(float radius);
void menu(void);
void all(void);

void main()

{
menu();
}

void areacircle(float radius)

{
double area;

area=PI*pow(radius,2);

printf("For radius=%.2f,area=%.2f\n",radius,area);

}

void circumferencecircle(float radius)

{
double circumference;

circumference=2*PI*radius;

printf("For radius=%.2f,circumference=%.2f\n",radius,circumference);

}

void all(void)

{
areacircle(10);
circumferencecircle(20);

}

void menu(void)

{
int choice;

printf("1. mengira kawasan bulatan\n");
printf("2. mengira lilitan bulatan\n");
printf("3. mengira semua\n");
printf("0. keluar\n");

printf("Please enter your choice:");
scanf("%d", &choice);

if(choice==1)

{
areacircle(10);

}

else if(choice==2)

{
circumferencecircle(20);
}

else if(choice==3)

{
all();

}

else if(choice==0)

{
printf("terima kasih..jumpa lagi..goodbye:)\a\a\a\a\n");

}

else

{

system("cls");
menu();

}

}

case


#include<stdio.h>

#define LEVEI1 0.10
#define LEVEI2 0.15
#define LEVEI3 0.20
#define LEVEI4 0.25


void main()
{

float meterReading;
double price;

char choice;

printf("-------------------------------------------------------------------------------\n");
printf("Syarikat Air Darul Aman Sdn. Bhd. <SADA>\n");
printf("Compute and display the water bill for the given meter readings\n");
printf("-------------------------------------------------------------------------------\n");
printf("1.     Compute and display water bill\n");
printf("2.     About\n");
printf("0.     Exit \n");
printf("-------------------------------------------------------------------------------\n");

printf("Please enter your choice=");
scanf("%c",&choice);

switch(choice)

{

case 'x':{}
case '1':{


printf("--------------------------------------------------------------\n");
printf("\nPlease enter the meter reading<unit>=");
scanf("%f", &meterReading);

if(meterReading>=0  &&  meterReading<=1000)

{

price=meterReading*LEVEI1;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);

}

else if(meterReading>=1001 && meterReading<=2000)

{

price=1000*LEVEI1 + (meterReading-1000)*LEVEI2;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);
printf("-------------------------------------------------------------------------\n\n");

}

else if(meterReading>=2001 && meterReading<=3000)

{

price=1000*LEVEI1 + 1000*LEVEI2 + (meterReading-1000)*LEVEI3;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);
printf("-------------------------------------------------------------------------\n\n");

}

else if(meterReading>3001)

{

price=1000*LEVEI1 - 1000*LEVEI2 - 1000*LEVEI3 + (meterReading-1000)*LEVEI4;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);


}

else

{

printf("You type the wrong number please try again");

}

 break;

}

case 'y':{}
case '2':{

printf("-------------------------------------------------------------------------------\n");
printf("**********************************ABOUT****************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("Syarikat Air Darul Aman Sdn. Bhd. <SADA>\n");
printf("Compute and display the water bill for the given meter readings\n");
printf("Version 2.1, Copyright 2012\n");
printf("Developer Name:Yosof Kadase, ykadase@gmail.com\n");
printf("-------------------------------------------------------------------------------\n");


break;

}


case 'o':{}
case '0':{

printf("BYE!\n");


break;

}

default:{


printf("Wrong/invalid input!\n");
printf("bye bye ! !\n");

}



}




}

case


#include<stdio.h>

#define LEVEI1 0.10
#define LEVEI2 0.15
#define LEVEI3 0.20
#define LEVEI4 0.25


void main()
{

float meterReading;
double price;

char choice;

printf("-------------------------------------------------------------------------------\n");
printf("Syarikat Air Darul Aman Sdn. Bhd. <SADA>\n");
printf("Compute and display the water bill for the given meter readings\n");
printf("-------------------------------------------------------------------------------\n");
printf("1.     Compute and display water bill\n");
printf("2.     About\n");
printf("0.     Exit \n");
printf("-------------------------------------------------------------------------------\n");

printf("Please enter your choice=");
scanf("%c",&choice);

switch(choice)

{

case 'x':{}
case '1':{


printf("--------------------------------------------------------------\n");
printf("\nPlease enter the meter reading<unit>=");
scanf("%f", &meterReading);

if(meterReading>=0  &&  meterReading<=1000)

{

price=meterReading*LEVEI1;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);

}

else if(meterReading>=1001 && meterReading<=2000)

{

price=1000*LEVEI1 + (meterReading-1000)*LEVEI2;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);
printf("-------------------------------------------------------------------------\n\n");

}

else if(meterReading>=2001 && meterReading<=3000)

{

price=1000*LEVEI1 + 1000*LEVEI2 + (meterReading-1000)*LEVEI3;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);
printf("-------------------------------------------------------------------------\n\n");

}

else if(meterReading>3001)

{

price=1000*LEVEI1 - 1000*LEVEI2 - 1000*LEVEI3 + (meterReading-1000)*LEVEI4;
printf("for meter reading is %.2f unit(s), the water bill is RM %.2f\n",meterReading,price);


}

else

{

printf("You type the wrong number please try again");

}

 break;

}

case 'y':{}
case '2':{

printf("-------------------------------------------------------------------------------\n");
printf("**********************************ABOUT****************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("Syarikat Air Darul Aman Sdn. Bhd. <SADA>\n");
printf("Compute and display the water bill for the given meter readings\n");
printf("Version 2.1, Copyright 2012\n");
printf("Developer Name:Yosof Kadase, ykadase@gmail.com\n");
printf("-------------------------------------------------------------------------------\n");


break;

}


case 'o':{}
case '0':{

printf("BYE!\n");


break;

}

default:{


printf("Wrong/invalid input!\n");
printf("bye bye ! !\n");

}



}




}

array 1


#include<stdio.h>

void main()

{

int total[4];
int a[3];
int b[3];
int no_loop;
int item;


item=3;
total[0]=0;
total[1]=0;
total[2]=0;
total[3]=0;



for(no_loop=0; no_loop<=2; no_loop++)

{
printf("enter the value of the item a[%d]:", no_loop);
scanf("%d", &a[no_loop]);
}

for(no_loop=0; no_loop<=2; no_loop++)

{
printf("enter the value of item b[%d]:", no_loop);
scanf("%d", &b[no_loop]);
}

for(no_loop=0; no_loop<=2; no_loop++)

{
total[2]=total[2]+(a[no_loop]*b[no_loop]);

}
for(no_loop=0; no_loop<=2; no_loop++)
{

total[0]=total[0]+a[no_loop];

}
for(no_loop=0; no_loop<=2; no_loop++)
{

total[1]=total[1]+b[no_loop];

}

printf("The sum total value a is %d\n",total[0]);
printf("The sum total value b is %d\n",total[1]);
printf("The sum of multiply of a and b is %d\n",total[2]);
printf("The total a x b divide a is %.2f\n\a",(float)total[2]/total[0]);

}

rimethic if else


#include<stdio.h>

void main()
{
int pilihan;
int x,y;

printf("1.. add\n");
printf("2.. Subtract\n");
printf("3.. Multiply\n");
printf("4.. Devide\n");
    printf("5.. Reminder\n");
{

printf("please select the operation (enter the number) as the above\n:");
scanf("%d",&pilihan);



if(pilihan==1)
{

       printf("please enter 2 number (add operation)\n\n");

printf("first number=\n");
scanf("%d",&x);

printf("second number=\n");
scanf("%d",&y);

printf("%d+%d = %d\n",x,y,x+y);


}

else if(pilihan==2)
{

       printf("please enter 2 number (subtract operation)\n\n");

printf("first number=\n");
scanf("%d",&x);

printf("second number=\n");
scanf("%d",&y);

printf("%d-%d = %d\n",x,y,x-y);
}

    else if(pilihan==3)
{

       printf("please enter 2 number (multiply operation)\n\n");

printf("first number=\n");
scanf("%d",&x);

printf("second number=\n");
scanf("%d",&y);

printf("%d*%d = %d/n",x,y,x*y);
}


    else if(pilihan==4)
{

       printf("please enter 2 number (devide operation)\n\n");

printf("first number=\n");
scanf("%d",&x);

printf("second number=\n");
scanf("%d",&y);

printf("%d/%d = %d\n",x,y,x/y);
}

    else if(pilihan==5)
{

       printf("please enter 2 number (add operation)\n\n");

printf("first number=\n");
scanf("%d",&x);

printf("second number=\n");
scanf("%d",&y);

printf("%d%%d = %d\n",x,y,x%y);

}

else
{

printf("maaf\n\n");
   printf("number anda tidak ditemui\n\n");
printf("sila cuba sekali lagi\n\n");
}

}
}