Human Factors of XR: Using Human Factors to Design XR Systems
Muzzammilrashid
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
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. 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. 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. 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. (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. (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. 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. 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. 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. 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. 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
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
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
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. #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. 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