0% found this document useful (0 votes)
3 views

Some C Code

Uploaded by

tungnthe153407
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Some C Code

Uploaded by

tungnthe153407
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<math.h>

// program find cube of number using function


void find_cube_number ( double n) {

double cube;
cube = n*n*n;
printf ("Cube of %f = %f",n ,cube);
}

double diameter_of_circle ( double r) {


return ( 2 * r); // tim duong kinh
}

double circumference_of_circle ( double r) {


return ( 2 * r * 3.14);
}

double area_of_circle (double r) {


return (r * r * 3.14);
}

int maximum ( int a , int b ) {


int max = a;
if ( max < b ) {
max = b;
}
return max;
}

int minimum ( int a , int b) {


int min = a ;
if ( min > b ) {
min = b;
}
return min ;
}

void even_odd ( int a ) {


if ( a % 2 == 0 ) {
printf ("%d is even", a);
} else {
printf ("%d is odd", a);
}
}

int check_prime ( int n) {


int count = 0;
if ( n < 2 ) {
return 0;
} else {
int i;
for ( i = 1 ; i <= n/2 ; i++) {
if ( n % i== 0 ) {
count++;
}
}
}
return count;
}

int perfect_number ( int n ) {


int i;
int sum = 0;
for ( i = 1 ; i < n ; i++) {
if ( n % i == 0 ) {
sum = sum + i;
}
}
return sum;

int main () {
printf ("Input any number:");
double n;
scanf ("%lf",&n );

find_cube_number(n);

printf ("\nEnter radius :");


double r;
scanf ("%lf", &r);

printf("Diameter = %f\n", diameter_of_circle(r));


printf("Circumference = %f\n", circumference_of_circle(r));
printf("Area = %f\n", area_of_circle(r));

printf ("\nEnter two number :");


int a,b;
scanf ("%d %d", &a, &b);

printf ("Maximum = %d\n", maximum(a,b));


printf ("Minimum = %d\n", minimum(a,b));

printf ("\nEnter a number you like :");


int number;
scanf ("%d",&number);

even_odd(number);

printf ("\nEnter a number :");


int c;
scanf ("%d",&c);

if (check_prime(c)==1) {
printf ("%d la so nguyen to ", c);
}
if (perfect_number(c)==c) {
printf ("%d la so hoan hao", c);
}
if (check_prime(c)!=1 && perfect_number(c)!=c) {
printf ("%d khong phai so nguyen to hay hoan hao ",c);
}
return 0;
}

You might also like