Linux Programming (CCS10903) Assignment 3
Linux Programming (CCS10903) Assignment 3
(CCS10903)
Assignment 3
Instruction to students:
• This is Individual lab practical.
• Complete this cover sheet and attach it to your assignment (first page).
Student declaration:
I declare that:
• This assignment is my own work
• I understand what is meant by plagiarism
• My lecturer has the right to deduct my marks in the case of:
- Late submission
- Any plagiarism found in my assignment.
Name Student ID
TOTAL
MARKS :
Linux Programming – CCS10903
Semester: September 2020
Assignment – 3
1. Write a GNU C program to read days, hours and minutes and convert
days to hours, hours to minutes and minutes to seconds. Declare
variable separately to convert days to hours, hours to minutes and
minutes to seconds.
3. Write a program that asks the user to enter two integers, then calculates
and displays their Greatest Common Divisor (GCD) and Least
Common Multiple (LCM) among the two.
Your submission should bind together with your Name, Student ID, Subject
name, and Assignment Number clearly written on the cover page. The cover
should be in YELLOW color. Submit your work to Dr. Asif Iqbal. H by 16
December 2020
1. Write a GNU C program to read days, hours and minutes and
convert days to hours, hours to minutes and minutes to seconds.
Declare variable separately to convert days to hours, hours to
minutes and minutes to seconds.
Source Code
#include <stdio.h>
int main() {
int sec, d, h, m, s;
scanf("%d", &sec);
h = (sec/3600);
m = (sec -(3600*h))/60;
s = (sec -(3600*h)-(m*60));
return 0;
}
Output
2. A number is special if it is exactly divisible by 7. A number is big if
it is greater than 9999. A number is weird if it is exactly divisible by
2 and 4 but not 8. A number is scary if it is big and weird. Write
a GNU C program to check which of the following, 822, 3227, 768
and 10086 are special but not scary. Declare four variables called
special, big, weird, and scary and make suitable assignments to
these variables as a number is tested.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
int n,special,big,weird,scary;
printf("Enter a number:");
scanf("%d",&n);
if(n%7==0)
special=n;
printf("Number is special.\n");
else
{
printf("Number is not special.\n");
if (n>999)
big=n;
printf("Number is big.\n");
else
weird=n;
printf("Number is weird.\n");
else
{
printf("Number is not weird.\n");
scary=n;
printf("Number is scary.");
else
getch();
return 0;
}
Output
Source Code
#include <stdio.h>
int main()
{
int n1, n2, i, gcd, max;
while (1) {
if (max % n1 == 0 && max % n2 == 0)
{
printf("The L.C.M of %d and %d is %d.", n1, n2, max);
break;
}
++max;
}
return 0;
}
OUTPUT