Created
October 28, 2022 16:04
-
-
Save anisur3036/a6cf6c1d16cc6a2b571211e7c59c1a98 to your computer and use it in GitHub Desktop.
First Assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//problem 01 | |
#include <stdio.h> | |
int main() | |
{ | |
int a = 5, b = 13; | |
// Write code here | |
int temp; | |
temp = a; | |
a = b; | |
b = temp; | |
// End of code | |
printf("%d and %d", a, b); | |
return 0; | |
} | |
//problem 02 | |
#include <stdio.h> | |
int main() | |
{ | |
int a, b, c, d, large_num, small_num; | |
scanf("%d %d %d %d", &a, &b, &c, &d); | |
if(a > b && a > c && a > d) | |
large_num = a; | |
if (b > c && b > d && b > a) | |
large_num = b; | |
if (c > d && c > a && c > b) | |
large_num = c; | |
if (d > a && d > b && d > c) | |
large_num = d; | |
if (a < b && a < c && a < d) | |
small_num = a; | |
if (b < c && b < d && b < a) | |
small_num = b; | |
if (c < d && c < a && c < b) | |
small_num = c; | |
if (d < a && d < b && d < c) | |
small_num = d; | |
printf("Largest = %d\n", large_num); | |
printf("Smallest = %d\n", small_num); | |
return 0; | |
} | |
//problem 03 | |
#include <stdio.h> | |
int main() | |
{ | |
long long int n; | |
int i = 0; | |
scanf("%lld", &n); | |
while (n > 0) | |
{ | |
n = n/10; | |
i++; | |
} | |
printf("%d", i); | |
return 0; | |
} | |
//problem 04 | |
#include <stdio.h> | |
int main() | |
{ | |
long long int n; | |
int last_digit; | |
int sum = 0; | |
scanf("%lld", &n); | |
while (n != 0) | |
{ | |
last_digit = n%10; | |
n = n/10; | |
sum = sum + last_digit; | |
} | |
printf("%d", sum); | |
return 0; | |
} | |
//problem 05 | |
#include <stdio.h> | |
int main() | |
{ | |
int n; | |
scanf("%d", &n); | |
while(n > 1) { | |
printf("%d, ", n); | |
if(n%2 == 0) { | |
n = n/2; | |
} else { | |
n = n - 1; | |
} | |
} | |
printf("%d, ", n); | |
return 0; | |
} | |
//problem 06 | |
#include <stdio.h> | |
int main() | |
{ | |
int first_num, second_num; | |
printf("Enter the first number: "); | |
scanf("%d", &first_num); | |
printf("Enter the second number: "); | |
scanf("%d", &second_num); | |
if(first_num%second_num == 0) | |
printf("The first number is divisible by the second number."); | |
else if (second_num%first_num == 0) | |
printf("The second number is divisible by the first number."); | |
else | |
printf("None of them are divisible by the other."); | |
return 0; | |
} | |
//problem 07 | |
#include <stdio.h> | |
int main() | |
{ | |
int a, b; | |
scanf("%d %d", &a, &b); | |
while (b) | |
{ | |
int temp = b; | |
b = a % b; | |
a = temp; | |
} | |
printf("%d", a); | |
return 0; | |
} | |
//problem 08 | |
#include <stdio.h> | |
int main() | |
{ | |
int a, b, gcd, lcm; | |
scanf("%d %d", &a, &b); | |
int multi = a * b; | |
while (b) | |
{ | |
int temp = b; | |
b = a % b; | |
a = temp; | |
} | |
gcd = a; | |
// we know that lcm = (a * b)/gcd | |
lcm = multi / gcd; | |
printf("%d", lcm); | |
return 0; | |
} | |
//problem 09 | |
#include <stdio.h> | |
int main() | |
{ | |
int n, i; | |
scanf("%d", &n); | |
printf("The factors of %d are: ", n); | |
for (i = 1; i <= n; i++) | |
{ | |
if(n%i == 0) { | |
printf("%d, ", i); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great