150 likes | 259 Views
Simple program. Computing 2009. 1. Customer buy items at supermarket. Cashier enter total amount of payment. Customer give their money and the cashier give back balance.
E N D
Simple program Computing 2009 Surie Aziz @ SMKDPM 2009
1 Customer buy items at supermarket. Cashier enter total amount of payment. Customer give their money and the cashier give back balance. Write a program to accept total payment and amount of customer’s money. Calculate and display the balance of money need to be returned to customer. Surie Aziz @ SMKDPM 2009
answer 1 Int main() { printf(“\nTotal Payment:”); scanf(“%f”,payment); printf(“\nCustomer Amount :”); scanf(“%f”,amount); balance=amount-payment; printf(“\nBalance = %f”,balance); return 0; } Surie Aziz @ SMKDPM 2009
2 Write a program to calculate a discounted price. Data need to be input are price and percent of discount. Surie Aziz @ SMKDPM 2009
answer 2 Int main() { printf(“\Price:”); scanf(“%f”,price); printf(“\nDiscount :”); scanf(“%d”,discount); discountprice=price-(price*discount)/100; printf(“\nPrice After Discount = %f”,discountprice); return 0; } Surie Aziz @ SMKDPM 2009
3 Write a program to ask user to a student name and his/her marks for BM, BI, Math, Geography and Science . From the marks calculate total and average marks. Display the name, all the marks, total and average. Surie Aziz @ SMKDPM 2009
answer Int main() { printf(“\nName:”); scanf(“%s”,name); printf(“\nBM Marks :”); scanf(“%d”,BM); printf(“\nBI Marks :”); scanf(“%d”,BI); printf(“\nMath Marks :”); scanf(“%d”,Math); printf(“\nGeography Marks :”); scanf(“%d”,Geog); printf(“\nScience Marks :”); scanf(“%d”,Sci); total=BM+BI+Math+Geog+Sci; Average=total/5 printf(“%s %d %d %d %d %d”,name,BM,BI,Math,Geog,Sci); return 0; } 3 Surie Aziz @ SMKDPM 2009
4 Write a program to ask user to enter 3 numbers. Display the biggest number. Surie Aziz @ SMKDPM 2009
answer 2 Int main() { printf(“\Enter 3 numbers:”); scanf(“%d %d %d”,num1, num2, num3); if (num1>num2) && (num1>num3) biggest=num1; if (num2>num1) && (num2>num3) biggest=num2; if (num3>num1) && (num3>num2) biggest=num3; return 0; } Surie Aziz @ SMKDPM 2009
5 Write a simple salary calculator. Data to be input are basic salary, allowance, bonus and taxdeduction. Calculate and display the salary received. NetSalary=BasicSalary+Allowance+Bonus-TaxDeduction Surie Aziz @ SMKDPM 2009
answer 5 Int main() { printf(“\nBasic Salary:”); scanf(“%f”,BasicSalary); printf(“\nAllowance :”); scanf(“%f”,Allowane); printf(“\Bonus :”); scanf(“%d”,Bonus); printf(“\Tax :”); scanf(“%d”,Tax); NetSalary=Basic+Allowance+Bonus-Tax; printf(“Salary Received= %f”,NetSalary); return 0; } Surie Aziz @ SMKDPM 2009
6 Each books returned late to the library will be fined 50 cents per day. Write a program to calculate total fined to be pay by the borrower. Prompt user for number of books and number of days (late returned) Surie Aziz @ SMKDPM 2009
answer 6 Int main() { printf(“\nNumber of Books Returned:”); scanf(“%d”,numBook); printf(“\nDays Late :”); scanf(“%d”,day); fine=numBook*day*0.50 printf(“Total Fine= %f”,fine); return 0; } Surie Aziz @ SMKDPM 2009
7 • Write a C program using pseudocode below : • 1. Start • 2. Ask user to enter a number from 1 to 9 or enter 0 to quit. • 3. If user enter 0, goto line • 4. If user enter number from 1 to 9 • 5. Display a box with row and columns using the number • entered by user. • (example if user enter 4, display box as below : • 4 4 4 4 • 4 4 4 4 • 4 4 4 4 • 4 4 4 4 • 6. Repeat line 2 • 7. End Surie Aziz @ SMKDPM 2009
answer Int main() { while (num!=0) { printf(“\nEnter number (1-9 / 0 to quit):”); scanf(“%d”,num); for(i=0;i<9;i++) { for(j=0;j<9;j++) { printf(“%d”,num); } printf(“\n”); } } return 0; } 7 Surie Aziz @ SMKDPM 2009