0% found this document useful (0 votes)
22 views14 pages

Baitapha

The document contains multiple code snippets in C programming language that demonstrate different concepts: 1) Calculating retail price by adding a percentage markup to the base price of a product. 2) Getting length and width values from user, calculating area, and displaying results. 3) Getting sales values for four regions, calculating totals, and finding the highest sales region. 4) Finding the number with the highest digit sum between two user-input values. 5) Defining a function to calculate the derivative of a power function. 6) Sorting an array of numbers in ascending and descending order by swapping elements.

Uploaded by

CHANNEL BST
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)
22 views14 pages

Baitapha

The document contains multiple code snippets in C programming language that demonstrate different concepts: 1) Calculating retail price by adding a percentage markup to the base price of a product. 2) Getting length and width values from user, calculating area, and displaying results. 3) Getting sales values for four regions, calculating totals, and finding the highest sales region. 4) Finding the number with the highest digit sum between two user-input values. 5) Defining a function to calculate the derivative of a power function. 6) Sorting an array of numbers in ascending and descending order by swapping elements.

Uploaded by

CHANNEL BST
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/ 14

S6.

1 )
#include <stdio.h>
#include <math.h>

float calculateRetail(float giasanpham , float tylegiatang)


{
float n = (giasanpham * tylegiatang)/100;
float giabanle = n + giasanpham;

return giabanle;
}

int main ()
{
float giasanpham , tylegiatang , kq ;

printf ("Nhap vao gia cua san pham nay : ");


scanf ("%f",&giasanpham);

printf ("Nhap vao ty le tang gia cua san pham nay : ");
scanf ("%f",&tylegiatang);

kq = calculateRetail (giasanpham , tylegiatang);


printf ("Gia ban le cua mat hang nay la : %.2f",kq);
}
6.2 )

#include <stdio.h>
#include <math.h>

void getLength(double &length)


{
printf ("Nhap vao gia tri cua length : ");
scanf ("%lf",&length);
}

void getWidth(double &width)


{
printf ("Nhap vao gia tri cua width : ");
scanf ("%lf",&width);
}

double getArea (double length , double width)


{
if (length < width)
{
int tam = length ;
length = width ;
width = tam ;
}
double area = width * length ;
return area;
}

void displayData(double length , double width , double area)


{
printf ("\nGia tri length la : %lf",length);
printf ("\nGia tri width la : %lf",width);
printf ("\nGia tri area la : %lf",area);
}
int main ()
{
double length , width ;
getLength (length);
getWidth (width);
double area = getArea(length , width);
displayData(length,width,area);
}
6.3 )
#include <stdio.h>
#include <math.h>

double getSales()
{
double thang1 , thang2 , thang3 , thang4 , tong;
printf ("Nhap vao doanh so ban hang thang 1 : \n");
scanf ("%lf",&thang1);
printf ("Nhap vao doanh so ban hang thang 2 : \n");
scanf ("%lf",&thang2);
printf ("Nhap vao doanh so ban hang thang 3 : \n");
scanf ("%lf",&thang3);
printf ("Nhap vao doanh so ban hang thang 4 : \n");
scanf ("%lf",&thang4);
return tong = thang1 + thang2 + thang3 + thang4 ;
}

void findHighest(double Northeast , double Southeast ,double


Northwest , double Southwest)
{

if (Northeast > Southeast && Northeast > Northwest &&


Northeast > Southwest )
{
printf ("Northeast co so luong ban hang cao nhat :
%lf",Northeast);
}
else
{
if (Southeast > Northeast && Southeast > Northwest
&& Southeast > Southwest )
{
printf ("Southeast co so luong ban hang cao
nhat : %lf",Southeast);
}
else
{
if (Northwest > Northeast && Northwest >
Southeast && Northwest > Southwest )
{
printf ("Northwest co so luong ban hang cao
nhat : %lf",Northwest);
}
else
{
printf ("Southwest co so luong ban hang cao
nhat : %lf",Southwest);
}
}
}

}
int main ()
{
double Northeast , Southeast , Northwest , Southwest ;

printf ("Nhap vao doanh so ban hang Northeast : \n");


Northeast = getSales ();
printf ("Nhap vao doanh so ban hang Southeast : \n");
Southeast = getSales ();
printf ("Nhap vao doanh so ban hang Northwest : \n");
Northwest = getSales ();
printf ("Nhap vao doanh so ban hang Southwest : \n");
Southwest = getSales ();
findHighest(Northeast , Southeast , Northwest ,
Southwest);

6.4 )
#include <stdio.h>
#include <math.h>
int main ()
{
int n , m , i , tam ;
int max = 0 ;
int x ;

printf ("Nhap vao 2 gia tri n va m (n<m) : ");

do
{
scanf ("%d",&n);
scanf ("%d",&m);
}while (n>=m);

for(i = n + 1 ; i < m ; i++)


{
int sodu = 0 ;
int tong = 0;
tam = i ;
while (tam > 0)
{
sodu = (tam % 10) ;
tam = tam / 10 ;
tong = tong + sodu;
}
if (tong >= max)
{
max = tong ;
x=i;
}
}
printf ("%d",x);

}
6. 5)
#include <stdio.h>
#include <math.h>

float fx(float a , float b)


{
float fx = b * pow(a,b-1);
return fx;
}

int main ()
{
float a , b ,kq ;
printf ("Nhap vao hai so a va b : ");
scanf ("%f%f",&a,&b);
kq = fx(a,b);
printf ("Gia tri dao ham la : %.2f",kq);
}
6.8)
#include <stdio.h>
#include <math.h>

void swap(int &a , int &b)


{
int tam = a ;
a=b;
b = tam;
}

void nhapso(int x[])


{
int i ;
printf ("Nhap vao cac chu so : ");
for (i = 0 ; i < 4 ; i++)
{
scanf ("%d",&x[i]);
}
}

void xuatso(int x[])


{
int i;
printf ("So vua nhap la : ");
for (i= 0 ; i < 4 ; i++)
{
printf ("%d",x[i]);
}
}

void sapxeptangdan(int x[])


{
int i , j ;
printf ("\nSap xep tang dan la : ");
for (i = 0 ; i < 4 ; i++)
{
int vtnn = i ;
for (j = i + 1 ; j < 4 ; j++)
{
if (x[j] < x[vtnn])
{
vtnn = j ;
}
}
swap(x[i],x[vtnn]);
printf ("%d",x[i]);
}
}

void sapxepgiamdan(int x[])


{
int i , j ;
printf ("\nSap xep giam dan la : ");
for (i = 0 ; i < 4 ; i++)
{
int vtln = i ;
for (j = i + 1 ; j < 4 ; j++)
{
if (x[j] > x[vtln])
{
vtln = j ;
}
}
swap(x[i],x[vtln]);
printf ("%d",x[i]);
}
}

int main ()
{
int x[4];
nhapso(x);
xuatso(x);
sapxeptangdan(x);
sapxepgiamdan(x);
}

You might also like