1 / 15

Simple program

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.

yoko
Download Presentation

Simple program

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Simple program Computing 2009 Surie Aziz @ SMKDPM 2009

  2. 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

  3. 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

  4. 2 Write a program to calculate a discounted price. Data need to be input are price and percent of discount. Surie Aziz @ SMKDPM 2009

  5. 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

  6. 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

  7. 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

  8. 4 Write a program to ask user to enter 3 numbers. Display the biggest number. Surie Aziz @ SMKDPM 2009

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

More Related