0% found this document useful (0 votes)
12 views11 pages

Code Asm1

The document contains code for a menu driven C program with multiple functions including checking if a number is integer, prime or perfect square, finding GCD and LCM of two numbers, calculating karaoke bill amount and a function to continue or exit the program. The main function calls the menu function and uses switch case to call respective functions based on user choice.

Uploaded by

Minh Kha Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views11 pages

Code Asm1

The document contains code for a menu driven C program with multiple functions including checking if a number is integer, prime or perfect square, finding GCD and LCM of two numbers, calculating karaoke bill amount and a function to continue or exit the program. The main function calls the menu function and uses switch case to call respective functions based on user choice.

Uploaded by

Minh Kha Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Code asm1:

#include <stdio.h>

#include <math.h>

#include <conio.h>

#include <string.h>

//Ham kiem tra so nguyen => true or false

int kiemtraso_nguyen(float x)

if(x == (int) x)

return 1;

else

return 0;

//Ham kiem tra so nguyen to

int kiemtraso_nguyento(int x)

int num = 0;

if(x <= 1)

printf("\n%d khong phai la so nguyen to", x);

return 0;

else

for(int i = 2; i <= sqrt(x); i++)


{

if(x % i == 0)

num++;

if(num == 0)

printf("\n%d la so nguyen to", x);

return 1;

else

printf("\n%d khong phai la so nguyen to", x);

return 0;

//Ham kiem tra so chinh phuong

int kiemtraso_chinhphuong(int x)

double test_num;

test_num = sqrt(x);

if (test_num == (int) test_num)

printf("\n%d la so chinh phuong", x);

return 1;

}
else

printf("\n%d khong phai la so chinh phuong", x);

return 0;

//Ham UCLN

int UCLN(int x, int y)

while(x != y)

if(x > y)

x -= y;

else

y -= x;

return x;

// Ham BCNN

int BCNN(int x, int y)

int result = UCLN(x, y);

return x*y/result;

}
//Ham tinh tien karaoke

float tinhTien (float time)

float tien;

if(time <= 3)

tien = time*150000;

else

tien = 3*150000 + (time - 3)*150000*70/100;

return tien;

// Ham xoa bo nho dem

void clear_stdin()

int c;

while ((c = getchar()) != '\n' && c != EOF) {}

//Ham lua chon co tiep tuc chuong trinh khong??

int get_choice()

char choice;

while (1)

clear_stdin();

printf("\nBan co muon tiep tuc chuong trinh (Y/N): ");

scanf("%c", &choice);
printf("\n");

if(choice == 'Y' || choice == 'y')

return 1;

else if(choice == 'N' || choice == 'n')

return 0;

else

printf("Lua chon khong hop le. Vui long chon Y hoac N.");

//Ham ve~ bang menu

void BangMenu(int dai, int rong)

int soKyTu_1, soKyTu_2, soKyTu_3, soKyTu_4, row;

char s1[] = "Chuc nang 1: Kiem tra so nguyen";

for (int i = 0; s1[i] != '\0'; ++i)

soKyTu_1 = i;

char s2[] = "Chuc nang 2: Tim Uoc sa chung va boi so chung cua 2 so";

for (int j = 0; s2[j] != '\0'; ++j)

soKyTu_2 = j;

char s3[] = "Chuc nang 3: Chuong trinh tinh tien cho quan Karaoke ";

for (int m = 0; s3[m] != '\0'; ++m)

soKyTu_3 = m;

char s4[] = "Chuc nang 4: Thoat";

for (int n = 0; s4[n] != '\0'; ++n)


soKyTu_4 = n;

// In dong 1:

row = 1;

printf("++");

while (row <= dai)

printf("-");

row++;

printf("++\n");

//In dong 2:

printf("|%s", s1);

row = soKyTu_1;

while (row <= dai)

printf(" ");

row++;

printf("|\n");

//In dong 3:

printf("|%s", s2);

row = soKyTu_2;

while (row <= dai)

{
printf(" ");

row++;

printf("|\n");

//In dong 4:

printf("|%s", s3);

row = soKyTu_3;

while (row <= dai)

printf(" ");

row++;

printf("|\n");

//In dong 5:

printf("|%s", s4);

row = soKyTu_4;

while (row <= dai)

printf(" ");

row++;

printf("|\n");

//In dong 6(final):

row = 1;
printf("++");

while (row <= dai)

printf("-");

row++;

printf("++\n");

//Ham chinh

int main()

BangMenu(56, 4);

int run_again = 1;

while(run_again)

int n;

printf("Xin moi chon chuc nang (1, 2, 3, 4): "); scanf("%d", &n);

switch (n)

case 1:

printf("CHUONG TRINH KIEM TRA SO NGUYEN - SO NGUYEN TO -


SO CHINH PHUONG!!");

float x;

printf("\nNhap x = "); scanf("%f", &x);

if(kiemtraso_nguyen (x))
{

printf("\n%.0f la so nguyen", x);

kiemtraso_nguyento(x);

kiemtraso_chinhphuong(x);

else

printf("\n%f khong phai la so nguyen \n=> Khong phai la


so nguyen to \n=> Khong phai la so chinh phuong", x);

break;

case 2:

printf("CHUONG TRINH TIM UOC CHUNG LON NHAT VA BOI


CHUNG NHO NHAT CUA 2 SO NGUYEN!!\n");

int x, y;

printf("Nhap so nguyen x: "); scanf("%d", &x);

printf("Nhap so nguyen y: "); scanf("%d", &y);

int result_1 = UCLN(x, y);

int result_2 = BCNN(x, y);

printf("Uoc chung lon nhat cua x va y la: %d\nBoi chung nho nhat
cua x va y la: %d", result_1, result_2);

break;

case 3:

printf("CHUONG TRINH TINH TIEN CHO QUAN KARAOKE!!");

int x, y, a, b;
printf("\nVui long nhap vao thoi diem bat dau va ket thuc (THEO
DUNG THOI GIAN TREN DONG HO)\n (12h - 23h)");

printf("\nNhap so gio bat dau (h): "); scanf("%d", &x);

printf("Nhap so phut bat dau (min): "); scanf("%d", &a);

printf("Nhap so gio ket thuc (h): "); scanf("%d", &y);

printf("Nhap so phut ket thuc (min): "); scanf("%d", &b);

printf("Thoi diem bat dau la: %dh%dmin", x, a);

printf("\nThoi diem ket thuc la: %dh%dmin", y, b);

if(x < 12 || x > 23 || a < 0 || a >= 60) goto exit;

if(y < 12 || y > 23 || b < 0 || b >= 60) goto exit;

//Khai bao bien tinh tong thoi gian (h)

float t_h = y - x, t_min = b - a, time = t_h + t_min/60;

if(time >= 0)

float tongTien;

if (x >= 14 && x <= 17)

tongTien = tinhTien(time)* 90/100;

else

tongTien = tinhTien(time);

printf("\nTong tien Karaoke la: %f", tongTien);

break;

}
exit:;

printf("Thoi gian khong hop le!");

break;

case 4:

printf("\nEXIT!!");

return 0;

default:

printf("Khong co chuc nang %d\nVui long nhap lai!!\n\n", n);

goto target;

printf("\nChuong trinh da hoan thanh.");

run_again = get_choice();

target:;

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy