TUANKU SULTANAH BAHIYAH POLYTECHNIC
ELECTRICAL ENGINEERING DEPARTMENT
EC201 – FUNDAMENTAL PROGRAMMING 1
SESION: JUN 2012

...
Please read the instructions / questions carefully.

EXERCISE 1 (3 HOURS)
Exercise 1A
Write a program that uses four outpu...
Exercise 1B
Use printf() function to write a program that prints your name, registration number, email
address and telepho...
Exercise 1C
Use puts() function to write a program that prints your name, registration number, email
address and telephone...
Exercise 1D
Fix the errors of the program below:
#include <stdio.h>
main()
{
char addresS [200];
puts("Insert your full ad...
Source Code
//Exercise 1D
#include<stdio.h>
main()
{
char address[200];
puts("Insert your full address");
gets(address);
p...
Exercise 1E:
A

C program contains the following statements:

#include <stdio.h>
Int I,j,k;
Write an appropriate scanf fun...
(b)

The values I will be decimal integer, j an octal integer and k a hexadecimal integer.
#include<stdio.h>
main()
{
int ...
(c)

The values for I and j will be hexadecimal integers and k will be an octal integer.
#include<stdio.h>
main()
{
int i,...
EXERCISE 2 ( 3 HOURS)
Exercise 2A:
Write the program and get the output.

//Exercise 2A
#include <stdio.h>
main()
{
char n...
Exercise 2B
Modify the add.c program;
i.

Subtraction of num1 and num2, then display the answer
Source Code

#include <std...
ii.

Multiplication of num1 and num2, then display the answer
Source Code

#include <stdio.h>
main()
{
char name [20];
int...
iii.

Division of num1 and num2, then display the answer
Source Code

#include <stdio.h>
main()
{
char name [20];
double n...
Exercise 2C
A C program contain s the following statement:
#include <stdio.h>
int a=0177,b=055,c=0xa8,d=0x1ff;

Write a pr...
(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...
Exercise 2D
Write a program that prompts the user to enter three numbers and then prints them vertically
(each in one line...
Source Code
#include <stdio.h>
main()
{
printf("Enter 3 integer : n");
printf("12 n");
printf("56 n");
printf("89 n");
pri...
EXERCISE 3 ( 3 HOURS)

Exercise 3A
By using the six steps in C programming, please make a program that can calculate volta...
#include<stdio.h>
main()
{
float resistance,current,voltage;
printf("---Ohm's Law---n");
printf("Enter resistance in Ohmn"...
Exercise 3B
By using the six steps in C programming, please make a program that can calculate the volume
and area of spher...
#include<stdio.h>
#define PI 3.142
main()
{
float radius,volume,area;
printf("Please enter the value for a radius:n");
sca...
Exercise 3C
By using the six steps in C programming, please make a program that can find odd or even
using conditional ope...
#include<stdio.h>

main()

{
printf("Enter an integern");
printf("5n");
printf(Odd numbernn");

return 0;

}

23
#include<stdio.h>

main()

{
printf("Enter an integern");
printf("6n");
printf("Even numbernn");

return 0;

}

24
PRACTICAL SKILL ASSESSMENT RUBRIC (CLO 4)
EXPERIMENT 2

1.Specifications

2.Readability

3.Error

/5

Exercise

/5

/5

4....
Upcoming SlideShare
Loading in …5
×

Muzzammilrashid

353 views
218 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
353
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
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
  6. 6. Source Code //Exercise 1D #include<stdio.h> main() { char address[200]; puts("Insert your full address"); gets(address); printf("Your address is :%sn",address); return 0; } 6
  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
  21. 21. #include<stdio.h> #define PI 3.142 main() { float radius,volume,area; printf("Please enter the value for a radius:n"); scanf("%f",&radius); area = 1.33*PI*(radius*radius*radius); printf("the volume is:%fn",area); volume = 4*PI*(radius*radius); printf("the area is:%f",volume); return 0; } 21
  22. 22. Exercise 3C By using the six steps in C programming, please make a program that can find odd or even using conditional operator. The sample of output you should get as shown below: *** Please make sure all the steps in problem solving are accurate and complete discussed 22
  23. 23. #include<stdio.h> main() { printf("Enter an integern"); printf("5n"); printf(Odd numbernn"); return 0; } 23
  24. 24. #include<stdio.h> main() { printf("Enter an integern"); printf("6n"); printf("Even numbernn"); return 0; } 24
  25. 25. PRACTICAL SKILL ASSESSMENT RUBRIC (CLO 4) EXPERIMENT 2 1.Specifications 2.Readability 3.Error /5 Exercise /5 /5 4.Concept Understanding /5 5.Delivery Total /5 /25 1A 1B 1C 1D 1E 2A 2B 2C 2D 3A 3B 3C Total Marks (( Total Mark/300)*100) /300 /100 25

×