Upcoming SlideShare
×

# Muzzammilrashid

353 views
218 views

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
353
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
2
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Muzzammilrashid

1. 1. TUANKU SULTANAH BAHIYAH POLYTECHNIC ELECTRICAL ENGINEERING DEPARTMENT EC201 – FUNDAMENTAL PROGRAMMING 1 SESION: JUN 2012 NAME : MATRIX NUM : COMPUTER NUMBER START TIME : END TIME : PRACTICAL SKILL MARK : : / 100 EXPERIMENT 2 TITLE : DATA INPUT AND OUTPUT Objectives At the end of this lesson, students will be able to understand: Input Output Statements Function of input output statements. a. printf() and puts() b. scanf() and gets() Use format specified in programs Modify input output file in programs Create input output operations. 1
2. 2. Please read the instructions / questions carefully. EXERCISE 1 (3 HOURS) Exercise 1A Write a program that uses four output statements to print the pattern of asterisks (*) shown below: ****** ****** ** ** ****** ****** * * * * * * * * * * * * * * * * * * * * ** * * ****** ****** *** *** ****** ****** Source Code //Exercise 1A #include <stdio.h> main() { printf("****** *** *** ******"); printf("n****** ** * ** ******"); printf("n ** ** ** **"); printf("n ** ** ** **"); printf("n****** **** ******"); printf("n****** * ******"); } 2
3. 3. Exercise 1B Use printf() function to write a program that prints your name, registration number, email address and telephone number. Source Code #include<stdio.h> main() { printf("Muhammad Muzzammil Bin Md Rasid n"); printf("16DET13F1112 n"); printf("muzzammil.rashid@gmail.com n"); printf("017-4408184 n"); printf("Muhammad Shahrizal Bin abdullah n"); printf("16DET13F1082 n"); printf("Haikal.mikail@yahoo.com n"); printf("017-5613319 n"); printf("Aliff Marican Bin Ibrahim Marican n"); printf("16DET13F1106 n"); printf("012-4428248 n"); printf("alip95@yahoo.com n"); printf("Muhamad Husaini bin Hilmi n"); printf("16DET13F1085n"); printf("husaini_potden@yahoo.comn"); printf("017-4236686 n"); return 0; } 3
4. 4. Exercise 1C Use puts() function to write a program that prints your name, registration number, email address and telephone number. Source Code #include<stdio.h> main() { puts("Muhammad Muzzammil Bin Md Rasid n"); puts("16DET13F1112 n"); puts("muzzammil.rashid@gmail.com n"); puts("017-4408184 n"); puts("Muhammad Shahrizal Bin abdullah n"); puts("16DET13F1082 n"); puts("Haikal.mikail@yahoo.com n"); puts("017-5613319 n"); puts("Aliff Marican Bin Ibrahim Marican n"); puts("16DET13F1106n"); puts("012-4428248 n"); puts("alip95@yahoo.com n"); puts("Muhamad Husaini bin Hilmi n"); puts("16DET13F1085 n"); puts("husaini_potden@yahoo.com n"); puts("017-4236686 n"); return 0; } 4
5. 5. Exercise 1D Fix the errors of the program below: #include <stdio.h> main() { char addresS [200]; puts("Insert your full address: "); getchs (Address); printf ("Your address is: %k n",address); return (); } The output after the errors fixed is shown as below: 5
7. 7. Exercise 1E: A C program contains the following statements: #include <stdio.h> Int I,j,k; Write an appropriate scanf function to enter numerical values for I,j and k, assuming (a) The values for I,j and k will be decimal integers. #include<stdio.h> main() { int i,j,k; printf("Insert value of i:n"); scanf("%d",&i); printf("Insert value of j:n"); scanf("%d",&j); printf("Insert value of k:n"); scanf("%d",&k); return 0; } 7
8. 8. (b) The values I will be decimal integer, j an octal integer and k a hexadecimal integer. #include<stdio.h> main() { int i,j,k; printf("Insert value of i:n"); scanf("%d",&i); printf("Insert value of j:n"); scanf("%f",&j); printf("Insert value of k:n"); scanf("%f",&k); return 0; } 8
9. 9. (c) The values for I and j will be hexadecimal integers and k will be an octal integer. #include<stdio.h> main() { int i,j,k; printf("Insert value of i:n"); scanf("%f",&i); printf("Insert value of j:n"); scanf("%f",&j); printf("Insert value of k:n"); scanf("%f",&k); return 0; } 9
10. 10. EXERCISE 2 ( 3 HOURS) Exercise 2A: Write the program and get the output. //Exercise 2A #include <stdio.h> main() { char name [20]; int num1,num2,answer; printf("Insert your name: "); scanf("%s",&name); printf("Enter your first integer:n"); scanf("%d",&num1); printf("Enter your second integer:n"); scanf("%d",&num2); answer=num1+num2; printf("The sum is : %dn",answer); return 0; } 10
11. 11. Exercise 2B Modify the add.c program; i. Subtraction of num1 and num2, then display the answer Source Code #include <stdio.h> main() { char name [20]; int num1,num2,answer; printf("Insert your name: "); scanf("%s",&name); printf("Enter your first integer:n"); scanf("%d",&num1); printf("Enter your second integer:n"); scanf("%d",&num2); answer=num1-num2; printf("The sum is : %dn",answer); return 0; } 11
12. 12. ii. Multiplication of num1 and num2, then display the answer Source Code #include <stdio.h> main() { char name [20]; int num1,num2,answer; printf("Insert your name: "); scanf("%s",&name); printf("Enter your first integer:n"); scanf("%d",&num1); printf("Enter your second integer:n"); scanf("%d",&num2); answer=num1*num2; printf("The sum is : %dn",answer); return 0; } 12
13. 13. iii. Division of num1 and num2, then display the answer Source Code #include <stdio.h> main() { char name [20]; double num1,num2,answer; printf("Insert your name: "); scanf("%s",&name); printf("Enter your first integer:n"); scanf("%d",&num1); printf("Enter your second integer:n"); scanf("%d",&num2); answer=num1/num2; printf("The sum is : %fn",answer); return 0; } 13
14. 14. Exercise 2C A C program contain s the following statement: #include <stdio.h> int a=0177,b=055,c=0xa8,d=0x1ff; Write a printf function for each of the following groups of variables or expressions. (a) a,b,c and d #include <stdio.h> main() { int a=0177 , b=055 , c=0xa8 , d=0x1ff; printf("a=0177 n"); printf("b=055 n"); printf("c=0xa8 n"); printf("d=0x1ff n"); return 0; } 14
15. 15. (b) (a+b), (c-d) #include <stdio.h> main() { int a=0177 , b=055 , c=0xa8 , d=0x1ff; printf("a=0177 n"); printf("b=055 n"); printf("c=0xa8 n"); printf("d=0x1ff n"); printf("(a+b), (c-d) n"); printf("(0177+055), (0xa8-0x1ff)"); return 0; } 15
16. 16. Exercise 2D Write a program that prompts the user to enter three numbers and then prints them vertically (each in one line), first forward and then reversed (the last one first), as shown below. 16
17. 17. Source Code #include <stdio.h> main() { printf("Enter 3 integer : n"); printf("12 n"); printf("56 n"); printf("89 n"); printf("forward order 12 -> 56 -> 89 n"); printf("reversed order 89 <- 56 <- 12 "); return 0; } 17
18. 18. EXERCISE 3 ( 3 HOURS) Exercise 3A By using the six steps in C programming, please make a program that can calculate voltage value using Ohms Law. The sample of output you should get as shown below: *** Please make sure all the steps in problem solving are accurate and complete discussed. 18
19. 19. #include<stdio.h> main() { float resistance,current,voltage; printf("---Ohm's Law---n"); printf("Enter resistance in Ohmn"); scanf("%f",&resistance); printf("Enter current in Amperen"); scanf("%f",&current); printf("Enter value of the Voltagen"); scanf("%f",&voltage); return 0; } 19
20. 20. Exercise 3B By using the six steps in C programming, please make a program that can calculate the volume and area of sphere. The sample of output you should get as shown below: *** Please make sure all the steps in problem solving are accurate and complete discussed 20