Skip to content

Instantly share code, notes, and snippets.

@nhatminhbui
Last active July 28, 2021 13:02
Show Gist options
  • Save nhatminhbui/d03d5ea66f0b390855e9820ff1f7577b to your computer and use it in GitHub Desktop.
Save nhatminhbui/d03d5ea66f0b390855e9820ff1f7577b to your computer and use it in GitHub Desktop.
#include <stdio.h>
const float pi = 3.14;
void ToChar(int); // 6a
void GetOrder(char); // 6b
void AreaVolumnGlob(float); // 7
void Power(int); // 8
void HourMinSec(unsigned int); // 9
void SumAllDigit(unsigned int); //10
int main () {
// functions go here
// scanf yourself
return 0;
}
// Bai 6. Buoi 2
void ToChar(int n) {
printf("%c", n);
}
void GetOrder(char c) {
printf("%d", c);
}
// Bai 7. Buoi 2
const float pi = 3.14;
void AreaVolumnGlob(float r) {
printf("Dien tich: %f\n", 4.0 * pi * r*r);
printf("The tich: %f", 4.0/3 * pi * r*r*r);
}
// Bai 8
void Power(int a) {
printf("a^2 = %d\n", a*a);
printf("a^3 = %d\n", a*a*a);
printf("a^4 = %d", a*a*a*a);
}
// Bai 9. Buoi 2.
void HourMinSec(unsigned int sec) {
unsigned int hour = sec / 3600;
unsigned int min = sec % 3600 / 60;
sec = sec % 3600 % 60;
printf("%02d:%02d:%02d", hour, min, sec);
}
// Bai 10. Buoi 2.
void SumAllDigit(unsigned int n) {
// n has exactly 5 digits
// unsigned sum = 0;
// for (; n>0; n/=10) sum += n % 10;
unsigned int sum = n % 10; n /= 10;
sum += n % 10; n /= 10;
sum += n % 10; n /= 10;
sum += n % 10; n /= 10;
sum += n % 10;
printf("So nut: %d", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment