Monday, 8 April 2013
rectangle
#include<stdio.h>
void main()
{
float panjang;
float lebar;
double hasil;
printf("\nMasukan nilai panjang segi empat sama");
scanf("%f",&panjang);
printf("\nMasukan nilai lebar segi empat sama");
scanf("%f",&lebar);
hasil=panjang*lebar;
printf("hasil darab %f dan %f adalah %f\n",panjang,lebar,hasil);
}
quiz
/*
Name: muhammad ifwat bin sallehuddin
Student ID: 51110113197
Group: L01 B01
Date: 28/2/2013
Question ID: s3st
*/
#include<stdio.h>
void main()
{
char choice;
float hour;
double price;
printf("Yosof Corporation Snd. Bhd\n");
printf("Compute and display wages\n");
printf("Please enter your choice by key-in the letters below\n");
printf("-----------------------------------------------------------\n");
printf("a. Computes and display hour\n");
printf("b. About\n");
printf("c. Exit\n");
printf("-----------------------------------------------------------\n");
printf("Please enter your choice:\n");
scanf("%c", &choice);
switch(choice)
{
case 'a':{}
case 'A':{
printf("Please enter your total hour:\n");
scanf("%f",&hour);
if(hour>=0 && hour<=40)
{
price=(4.00*hour);
printf("Your total hour: %.0f/hour\n", hour);
printf("Your total payment:RM %.2f\n", price);
}
else if(hour>=41 && hour<=60)
{
price=((4.00*40)+(8.00*(hour-40)));
printf("Your total hour: %.0f/hour\n", hour);
printf("Your total payment:RM %.2f\n", price);
}
else if(hour>=61 && hour<=100)
{
price=((4.00*40)+(8.00*40)+(15.00*(hour-40)));
printf("Your total hour: %.0f/hour\n", hour);
printf("Your total payment:RM %.2f\n", price);
}
else if(hour>=101)
{
price=((4.00*40)+(8.00*40)+(15.00*40)+(25.00*(hour-40)));
printf("Your total hour: %.0f/hour\n", hour);
printf("Your total payment:RM %.2f\n", price);
}
else
{
printf("Wrong/invalid input\n");
printf("Bye! Bye!\n");
}
}
break;
case 'b':{}
case 'B':{
printf("**********************About********************************\n");
printf("-----------------------------------------------------------\n");
printf("Yosof Corporation Sdn. Bhd\n");
printf("Compute and display wages\n");
printf("Version 1.1, Copyright 2011\n");
printf("-----------------------------------------------------------\n");
}
case 'c':{}
case 'C':{
printf("Wrong\n");
break;
}
default:{ printf("bye bye\n");
}
}
}
password
#include<stdio.h>
void main()
{
int password;
int umur;
printf("masukkan password:");
scanf("%d",&password);
printf("masukkan umur anda:");
scanf("%d",&umur);
if(password==12345 && umur>=21)
printf("tahniah password anda betul\n");
else
printf("password salah dan anda sudah tua\n");
}
name
#include<stdio.h>
void main()
{
printf("My name is muhammad ifwat\n");
printf("I am 21 years old\n");
printf("My ID is 51110113197\n");
printf("My IC number is 920806106069\n");
}
nama subject
#include<stdio.h>
#include<windows.h>
void main()
{
char subjekName[10];
int x;
for(x=0;x<=9;x++)
{
printf("masukkan nama subjek ke %d:",x+1);
scanf("%s", &subjekName);
}
system("cls");
printf("--------------------------------------------------------------------------------------------------\n");
for(x=0;x<=9;x++)
{
printf("nama subjek ke %d adalah %s\n",x+1,subjekName[x]);
printf("----------------------------------------------------------------------------------------------\n");
}
}
mini call funtion
#include<stdio.h>
void add(int x, int y);
void subtract(int x, int y);
void multiply(int x, int y);
void divide(int x, int y);
void remainder(int x, int y);
int choice;
void main()
{
printf("1. add\n");
printf("2. devide\n");
printf("3. multiply\n");
printf("4. divide\n");
printf("5. remainder\n");
printf("sila buat pilihan anda:");
scanf("%d", &choice);
if(choice==1)
{
int a,b;
printf("\nMasukkan integer pertama:");
scanf("%d", &a);
printf("\nMasukkan integer kedua:");
scanf("%d", &b);
add(a,b);
}
else if(choice==2)
{
int a,b;
printf("\nMasukkan integer pertama:");
scanf("%d", &a);
printf("\nMasukkan integer kedua:");
scanf("%d", &b);
subtract(a,b);
}
else if(choice==3)
{
int a,b;
printf("\nMasukkan integer pertama:");
scanf("%d", &a);
printf("\nMasukkan integer kedua:");
scanf("%d", &b);
multiply(a,b);
}
else if(choice==4)
{
int a,b;
printf("\nMasukkan integer pertama:");
scanf("%d", &a);
printf("\nMasukkan integer kedua:");
scanf("%d", &b);
divide(a,b);
}
else if(choice==5)
{
int a,b;
printf("\nMasukkan integer pertama:");
scanf("%d", &a);
printf("\nMasukkan integer kedua:");
scanf("%d", &b);
remainder(a,b);
}
}
void add(int x, int y)
{
int hasil;
hasil=x+y;
printf("Hasil tambah %d dan %d ialah %d\n",x,y,hasil);
}
void subtract(int x, int y)
{
int hasil;
hasil=x-y;
printf("Hasil tolak %d dan %d ialah %d\n",x,y,hasil);
}
void multiply(int x, int y)
{
int hasil;
hasil=x*y;
printf("Hasil darab %d dan %d ialah %d\n",x,y,hasil);
}
void divide(int x, int y)
{
int hasil;
hasil=x/y;
printf("Hasil bahagi %d dan %d ialah %d\n",x,y,hasil);
}
void remainder(int x, int y)
{
int hasil;
hasil=x%y;
printf("Hasil bagi %d bahagi %d ialah %d\n",x,y,hasil);
}
mini call all
#include<stdio.h>
void menu(void);
void smallMenu(void);
float getInteger(void);
float value(float num);
float add(float x, float y);
float sub(float x, float y);
float multiple(float x, float y);
float divide(float x, float y);
float reminder(float x, float y);
void displayAdd(float x, float y, float result);
void displaySub(float x, float y, float result);
void displayMultiple(float x, float y, float result);
void displayDivide(float x, float y, float result);
void displayReminder(float x, float y, float result);
void main()
{
menu();
}
void menu(void)
{
int choice;
printf("1. Addition\n");
printf("2. Substraction\n");
printf("3. Multiple\n");
printf("4. Divide\n");
printf("5. Reminder\n");
printf("0. Exit\n");
printf("Please enter your choice:");
scanf("%d", &choice);
if(choice==1)
{
float a,b;
float result;
a=getInteger();
b=getInteger();
result=add(a,b);
displayAdd(a,b,result);
}
else if(choice==2)
{
float a,b;
float result;
a=getInteger();
b=getInteger();
result=sub(a,b);
displaySub(a,b,result);
}
else if(choice==3)
{
float a,b;
float result;
a=getInteger();
b=getInteger();
result=multiple(a,b);
displayMultiple(a,b,result);
}
else if(choice==4)
{
float a,b;
float result;
a=getInteger();
b=getInteger();
result=divide(a,b);
displayDivide(a,b,result);
else if(choice==5)
{
float a,b;
float result;
a=getInteger();
b=getInteger();
result=reminder(a,b);
displayReminder(a,b,result);
}
else if(choice==0)
{
printf("Thank You and Bye...\n");
}
else
{
menu();
}
}
void smallMenu(void)
{
int choice;
printf("1. Menu\n");
printf("0. Exit\n");
printf("Please enter your choice:");
scanf("%d", &choice);
if(choice==1)
{
menu();
}
else if(choice==0)
{
printf("Thank You and Bye...\n");
}
else
{
smallMenu();
}
}
float getInteger(void)
{
float num;
printf("Please enter your value:");
scanf("%f", &num);
return num;
}
float add(float x, float y)
{
return x+y;
}
float sub(float x, float y)
{
return x-y;
}
float multiple(float x, float y)
{
return x*y;
}
float divide(float x, float y)
{
return x/y;
}
float reminder(float x, float y)
{
return x/y;
}
void displayAdd(float x, float y, float result)
{
printf("%.2f + %.2f = %.2f\n",x,y,result);
}
void displaySub(float x, float y, float result)
{
printf("%.2f - %.2f = %.2f\n",x,y,result);
}
void displayMultiple(float x, float y, float result)
{
printf("%.2f * %.2f = %.2f\n",x,y,result);
}
void displayDivide(float x, float y, float result)
{
printf("%.2f / %.2f = %.0f\n",x,y,result);
}
void displayReminder(float x, float y, float result)
{
printf("%.2f / %.2f = %.2f\n",x,y,result);
}
Subscribe to:
Posts (Atom)