WIndows 8

New Microsoft OS.

Majalah PC

"Majalah Pc" is Malay version of ICT magazine that have many useful information about computer.

LiveWatch V

Telefon Pintar sebagai Jururawat.

Bitdefender Antivirus and Internet Security 2013 software and key

You can download for free. The key is cheap.

Showing posts with label Programming Exercise. Show all posts
Showing posts with label Programming Exercise. Show all posts

Thursday, 2 August 2012

Looping : conditional statements

Conditional Statements
The owner of SAYANG restaurant distributes brochures to his customers informing discounts
offered on selected menu for the month of July. To be eligible for the discount, a customer
must order any three items of the menu. The discount for each item in the menu is shown in
the table below.
Item
No. Menu Discount
1. Appetizers 10%
2 .Salads 10%
3 .Soups 20%
4 .Seafood 8%
5 .Chicken/Beef 15%
6 .Noodles/Rice 20%
7 .Vegetables 25%
8 .Pasta 15%
9 .Beverages 20%
10. Lunch Special 25%
11 .Healthy Food 15%
12 .Others 5%
The restaurant owner has requested you to write a program in C that reads the three ordered
items and their normal prices. The program calculates the total amount to be billed to the
customer based on the discount given for each item.


Monday, 18 June 2012

Programming Exercise 2: Calculator Program

Write a calculator program that takes two (integer) numbers as input and allows the user to select which operation they would like to perform on the two number, either:



  • Addition 
  • Subtraction 
  • Multiplication 
  • Division 
and display the result: Terminate the program when enter 'n'

The Answer is

‎#include <stdio.h>


int main()


{


float num1, num2;


char operation;


while (1) {


printf("Please enter 2 integer:");
scanf("%f%f", &num1, &num2);
printf("Enter an option(A for addition, B for subtraction, C for multiplication,\n D for division, n for exit):");
scanf("%s", &operation);


if (operation == 'A')


printf("%f\n", num1+num2);


if (operation == 'B')


printf("%f\n", num1-num2);


if (operation == 'C')


printf("%f\n", num1*num2);


if (operation == 'D')


printf("%f\n", num1/num2);


if (operation == 'n')


break;


}


}

Programming Exercise 1 : for

Write a program that accept one digit and display in triangle:
Example

input: 5
output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

The C Program Is :

#include<stdio.h>
void main()

{
int i, n, j;
printf ("\n Please Enter Single Digit Number");
scanf("%d",&n);
for(i=1; i<=n; i++)
     {
      for(j=1; j<=i; j++)
      printf("%d",j);
      printf("\n");
      }
}