fork download
  1. //bai 1
  2. #include <stdio.h>
  3. int main(){
  4. int n;
  5. int a = 0;
  6. printf("Nhap so n: ");
  7. scanf("%d", &n);
  8. for (int i = 1; i <= n; i++) {
  9. a += i;
  10. }
  11. printf("Tong cua day tu 1 toi %d la = %d\n", n, a);
  12. return 0;
  13. }
  14.  
  15. //bai2
  16. #include <stdio.h>
  17. int main(){
  18. int n;
  19. int a = 0;
  20. printf("Nhap so n: ");
  21. scanf("%d", &n);
  22. int b = n;
  23. while (b > 0){
  24. a++;
  25. b = b / 10;
  26. }
  27. printf("So %d co %d chu so.\n", n, a);
  28. return 0;
  29. }
  30.  
  31. //bai 3
  32. #include <stdio.h>
  33. int main(){
  34. float diem;
  35. do{
  36. printf("Nhap diem kiem tra :");
  37. scanf("%f", &diem);
  38. }
  39. while (diem < 0 || diem > 10);
  40. printf("Ban da nhap diem sau: %.1f\n", diem);
  41. return 0;
  42. }
  43.  
  44. //bai 5
  45. #include <stdio.h>
  46. int main(){
  47. int n;
  48. printf("Nhap so nguyen n: ");
  49. scanf("%d", &n);
  50. if (n >= 2){
  51. printf("Cac so nguyen to tu 2 den %d la: ", n);
  52. for (int i = 2; i <= n; i++){
  53. int dem = 0;
  54. for (int j = 1; j <= i; j++) {
  55. if (i % j == 0) {
  56. dem++;
  57. }
  58. }
  59. if (dem == 2) {
  60. printf("%d ", i);
  61. }
  62. }
  63. printf("\n");
  64. }
  65. return 0;
  66. }
  67.  
  68.  
  69. //bai 6
  70. #include <stdio.h>
  71. int main(){
  72. int n;
  73. printf("Nhap so hang n: ");
  74. scanf("%d", &n);
  75. if (n > 0) {
  76. for (int i = n; i >= 1; i--) {
  77. for (int j = 1; j <= i; j++) {
  78. printf("* ");
  79. }
  80. printf("\n");
  81. }
  82. } else {
  83. printf("Vui long nhap lai\n");
  84. }
  85. return 0;
  86. }
Compilation error #stdin compilation error #stdout 0s 5316KB
stdin
Standard input is empty
compilation info
prog.c:17:5: error: redefinition of ‘main’
 int main(){
     ^~~~
prog.c:3:5: note: previous definition of ‘main’ was here
 int main(){
     ^~~~
prog.c:33:5: error: redefinition of ‘main’
 int main(){
     ^~~~
prog.c:3:5: note: previous definition of ‘main’ was here
 int main(){
     ^~~~
prog.c:46:5: error: redefinition of ‘main’
 int main(){
     ^~~~
prog.c:3:5: note: previous definition of ‘main’ was here
 int main(){
     ^~~~
prog.c:71:5: error: redefinition of ‘main’
 int main(){
     ^~~~
prog.c:3:5: note: previous definition of ‘main’ was here
 int main(){
     ^~~~
prog.c: In function ‘main’:
prog.c:7:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ^~~~~~~~~~~~~~~
prog.c: In function ‘main’:
prog.c:21:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ^~~~~~~~~~~~~~~
prog.c: In function ‘main’:
prog.c:37:9: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%f", &diem);
         ^~~~~~~~~~~~~~~~~~
prog.c: In function ‘main’:
prog.c:49:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ^~~~~~~~~~~~~~~
prog.c: In function ‘main’:
prog.c:74:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ^~~~~~~~~~~~~~~
stdout
Standard output is empty