Practical 2
Practical 2
Practical 2
Open your Quincy 2005 version and select C Source file to practice the given codes.
This practical sheet designed to practice the scan function scanf() and print function printf() in C
Programming.
printf( )
In C programming language, printf() function is used to print the (“character, string, float, integer, octal
and hexadecimal values”) onto the output screen.
We use printf() function with %d format specifier to display the value of an integer variable.
Similarly, %c is used to display character, %f for float variable, %s for string variable, %lf for double
and %x for hexadecimal variable.
To generate a newline, we use “\n” in C printf () statement.
scanf( )
In C programming language, scanf() function is used to read character, string, numeric data from
keyboard.
Activity 01
#include<stdio.h>
int main ()
{
/*This line is for defining Age variable to hold the value*/
int Age;
/* Enter different Age’s through the key board and see the outputs*/
scanf(“%d”, &Age);
Page 1 of 2
return 0;
}
2. Following program is designed to ask the first name of the user, and print it in a message. Try to
program it and compile it.
#include<stdio.h>
int main(){
/*Defining a variable to store a name of the user that limits to 20 characters .*/
char name[20];
return 0;
}
3. Following program is designed to enter two numbers and print the total number. Try to do it.
#include<stdio.h>
int main(){
int a,b;
int total;
printf("First number:");
scanf("%d",&a);
printf(“Second number:”);
scanf(“%d”,&b);
total=a+b; printf("Total:
%d”,total);
return 0;
}
4. Write a program to input marks of three subjects. Calculate and print the total and the
Average marks. (Hint: Create two different variables to store total and the average)
5. Write a program to input temperature in Fahrenheit and to calculate and print the equivalent
temperature in Celsius.
C = (5/9)*(F-32)
C – Celsius Value
F – Fahrenheit Value
Page 2 of 2