Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
74 views

Linux Programming (CCS10903) Assignment 3

The document is an assignment for a Linux programming course. It contains 3 programming problems to solve: 1) a program to convert between days, hours, minutes and seconds, 2) a program to check properties of numbers like being special, big, weird or scary, and 3) a program to calculate the greatest common divisor and least common multiple of two integers input by the user. The cover page includes student details and submission instructions.

Uploaded by

Intan Nasuha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Linux Programming (CCS10903) Assignment 3

The document is an assignment for a Linux programming course. It contains 3 programming problems to solve: 1) a program to convert between days, hours, minutes and seconds, 2) a program to check properties of numbers like being special, big, weird or scary, and 3) a program to calculate the greatest common divisor and least common multiple of two integers input by the user. The cover page includes student details and submission instructions.

Uploaded by

Intan Nasuha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Linux Programming

(CCS10903)
Assignment 3

Received Date : 3/12/2020


Submission Date : 16/12/2020
Weightage : 10 %
Semester : September 2020
Lecturer : Dr. Asif

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

INTAN NASUHA BT RUSLIZAN 012018091145

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. 

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. 

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;

printf("Input seconds: ");

scanf("%d", &sec);

d = (sec / (24 * 3600));

h = (sec/3600);

m = (sec -(3600*h))/60;

s = (sec -(3600*h)-(m*60));

printf(" Days : %d\n Hours : %d\n Minutes : %d\n Seconds:


%d\n ",d,h-24,m,s);

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

printf("Number is not big.\n");

if(n%2==0 && n%4==0 && n%8!=0)

weird=n;

printf("Number is weird.\n");

else

{
printf("Number is not weird.\n");

if(n==big && n==weird)

scary=n;

printf("Number is scary.");

else

printf("Number is not scary.");

getch();

return 0;

}
Output

Input number: 822

Input number: 768

Input number: 3227


Input number: 10086
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.

Source Code

#include <stdio.h>
int main()
{
int n1, n2, i, gcd, max;

printf("Enter two integers: ");


scanf("%d %d", &n1, &n2);

for(i=1; i <= n1 && i <= n2; ++i)


{
// Checks if i is factor of both integers
if(n1%i==0 && n2%i==0)
gcd = i;
}

printf("The G.C.D of %d and %d is %d.\n", n1, n2, gcd);

// maximum number between n1 and n2 is stored in min


max = (n1 > n2) ? n1 : n2;

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

You might also like