0% found this document useful (0 votes)
4 views2 pages

ProgrammingLab (1) One BasicProgramInstruction

The document provides instructions and exercises for programming in C, emphasizing the use of IDEs, variables, and functions. It includes problems to practice writing the main function, displaying output, declaring variables, and taking user input. The exercises guide users through basic programming concepts and syntax in C.

Uploaded by

20254103224
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

ProgrammingLab (1) One BasicProgramInstruction

The document provides instructions and exercises for programming in C, emphasizing the use of IDEs, variables, and functions. It includes problems to practice writing the main function, displaying output, declaring variables, and taking user input. The exercises guide users through basic programming concepts and syntax in C.

Uploaded by

20254103224
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Week Four Instructions and Exercises

1. Open an Integrated Development Environment (IDE): Visual Studio, or Visual Code, or


CodeBlocks.
2. Software programs are created
a. to store information/data of humans, and
b. to do functionalities for humans.
3. In a program
a. To store information, we use variables.
b. To do stuff/functionalities, we use functions.
4. One function is must in C. Do you know what is that function? It is the “main” function.
5. When a program needs to do something,
a. it either does it in the main() function or
b. calls another function from main() function to do it for him.
6. We always start with a problem to solve. To solve it, we first design the solution of the problem.
A design is the step by step solution of the problem. First find the steps of the solution. Then
write each step as a comment. Make it an everyday programming practice. Here are two ways to
write comments. Put one line comment at the top of your program stating what that program
does.
a. // This is a comment using double forward slash for single line comment
b. For multiple lines comment surround the text with “/*” and “*/”.
7. Problem 1: As the “main” function is a must, let us write it.
void main(){
}
8. Now, run the program.
9. To use a function,
a. The function needs to exist
i. As a library function, or
ii. We need to create it. We will not create any function in ICS.
b. We need to call it by name
i. passing any input (we call it “argument”) if required.
10. Problem 2: Write a Program that will display “Hello World”.
a. We need to display. We need to use a function to display something. Here “Hello World”
is called a string. There is a function called “printf” that we can use to display “Hello
World”. “printf” doesn’t know what to display. So, we need to pass “Hello World” to
“printf”. “printf” takes at least one argument, and that argument is a string. A string is
anything within two double quotes.
b. Let’s call printf passing the string “Hello World”.
Output
Hello World
11. Problem 3: Write a Program that will use newline (\n) and print the following segment.
Output
Hello Programmers.
Welcome to C Programming.
12. What are variables? – We have data everywhere. In programs, we use variables to store those
data.
a. Before we can use a variable, we need to declare/define them
13. Variable declaration:
a. [variable type][space][variable name][;]
b. variable naming rules
14. Problem 4: Store an age.
a. An age is a whole number. To store whole number we need an integer type variable. The
keyword to declare an integer variable is “int”.
b. Declare an integer variable “age”: [variable type][space][variable name][;]
i. int age;
15. Problem 5: (i) Store a score of a class test. A score is usually a float number. You need to use the
keyword “float” as the variable type. (ii) Store a letter grade of a course. A grade is usually a
character. You need to use the keyword “char” as the variable type. A character is written within
two single quotes.
16. Problem 6: Display the value of variable “age”. To display we need to call “printf”. To display the
value of a variable, we need to pass it to printf after the double quoted string separated by a
comma. We need to tell printf the format of the variable in the string argument with a format
specifier. A format specifier starts with a % sign followed by an alphabet. For integer, it is d.
Hence, for age, we pass %d in the string.
Sample output
My age is: 20
17. Problem 8: Write a Program (WAP) that will do the followings:
a) Declare an integer variable a uninitialized, and display it. Is there any error?
b) Declare and initialize an integer variable b (in one statement), and display it.
c) Declare and initialize multiple integer variables c, d, e with different values in one statement and
display them.
18. Problem 7: Write a Program that will declare and initialize an integer, a floating point number,
and a character. Print those values.
Sample output
The integer value: 11
The floating point value: 3.14
The character value: h
19. Problem 9: Take an “age” value from user. To take an input from user, we need to use the
“scanf” function. Like printf, scanf also takes a string with a format specifier followed by variable
name(s) separated comma(s). There is an ampersand (&) before the variable name.
a. scanf(“%d”, &age);
20. Problem 10: Write a Program (WAP) that will take the values of an integer, a floating point
number, and a character from the keyboard and print those values in one statement.
a. You need to use “ %c”(notice the space before % sign) to specify the character format.

Sample input Sample output


5 The integer value: 5
3.141593 The floating point value: 3.141593
a The character value: a
100 1.618 z The integer value: 100
The floating point value: 1.618000
The character value: z
21. Problem 11: Write a Program (WAP) that will take three integer numbers from keyboard at once
(using one function call) and prints only the last value.
Sample input Sample output
20 50 100 Last Value = 100

You might also like