C Language Practice Tasks
C Language Practice Tasks
Applied Sciences
1. Using Mobile Without Permission Will Be Marked As Absent And 50% Marks Of This
Lab Will Be Deducted.
2. Copying Assignment / Using the internet During Lab tasks and Marking Proxy will Lead
you to an “F” Grade in the Lab. Be very careful.
3. Use an appropriate naming convention for variable name. e.g to calculate the sum of the
number variable name can be sum, sum_of_number. Random variable names are not allowed.
4. Lab Tasks must be submitted in pdf with a screen shot of output.
5. File name should be as
Degree_Full Name
6. Submission Deadline of Lab Task is on the same day, during Lab, by 10:20 am
Topics Covered
1. If statements
2. If else statements
3. If else if statements
4. Break Statement
5. Continue Statement
6. Exit function
SA - Task -1
Write a c program which declare arithmetic assignment operators with declaration of variables
and display the mathematical expressions on the screen.
SA- Task -2
Write a c program which describe of increment operators ++ and display these on the screen.
getchar(); return 0;
}
Write a c program which describe of decrement operators -- and display these on the screen.
getchar(); return 0;
}
SA- Task -4
#include<stdio.h>
int main()
{
int a = 7, b = 20, c, d;
c = a++;
printf("%d", c);
printf("\n%d",a);
d = ++b;
printf("\n%d", d);
printf("\n%d",b);
getchar(); return 0;
}
WL - Task -1
Write a similar c program which initialize variable V =20, declare variable d,c and apply
increment and decrement by one number
Output
Syntax
if (condition) {
// block of code to be executed if the condition is true
}
SA – Task 5
#include<stdio.h>
int main()
{
int num;
printf("Please enter an integer number:\n");
scanf("%d",&num);
if(num%2==0)
printf("\nThe number %d is an even
number",num);
if(num%2!=0)
printf("\nThe number %d is an odd
number",num);
getchar(); getchar();
return 0;
}
WL - Task -2
Write a C program using if else statement for detecting even or odd number
Output
Syntax
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
WL - Task -3
Write a C program to implement using if else statement, if age is less than 16 print “ Go
to Child Specialist Room 10 otherwise go to Adult Specialist room number 9
WL - Task -4
Write a C program using if else statement, If age is less than 12 print The Fee is 500
otherwise Fee is 200.
Output
Output
WL - Task -6
Output
Syntax
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is
true
} else {
// block of code to be executed if the condition1 is false and condition2 is
false
}
WL - Task -7
Ouput
WL - Task -08
Write a C program which takes two input numbers (x and y) from user if x is greater
than y “print x is greater than y” if x =y, print “x is equal to y” if x is less than y print “x is
smaller than y”
Syntax:
Output:
value of variable num is: 0
value of variable num is: 1
value of variable num is: 2
Out of while-loop
SA Task -07
Output:
var: 100
var: 99
Out of for-loop
Write a C program that takes a sequence of integers from the user using a for loop. Display
each integer and break the loop if the user enters a number that is a multiple of 7.
Continue Statement
The continue statement in C programming works somewhat like the break statement. Instead
of forcing termination, it forces the next iteration of the loop to take place, skipping any code in
between. For the for loop, continue statement causes the conditional test and increment portions of
the loop to execute.
Syntax:
Output:
10986543210
SA Task -09
Output:
0, 1, 2, 3, 4, 5, 6, 8, 9
Write a C program that reads 10 numbers from the user using a for loop. Calculate and print
the sum of all numbers divisible by 3, skipping the others using the continue statement.
exit() function
Description
The C library function void exit(int status) terminates the calling process immediately.
WL Task 11
Write a c program which exit itself when someone enter 0.
WL Task 12
For a school develop a program which assists teachers by displaying the respective grade of
student when marks are entered. Teacher will enter Marks and a Letter grade should be
displayed as per following breakdown: