-
17-05-2015, 02:09 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Đang ở
- hà nội
- Bài viết
- 0
các bác check giúp e với. cảm ơn cả nhà ạ
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
long factorial( int n)
{
int i, mul;
mul=1;
for (i=1; i<=n; i++)
mul = mul*i;
return(mul);
}
int main()
{
char choices;
printf("1. Convert decimal to binary
");
printf("2. Compute square root n times
");
printf("3. Solve a quadratic equation
");
printf("4. Print something fun
");
printf("q. Quit the program
");
printf("Your choice is ");
scanf("%c", &choices);
if( choices == '1')
{
int bin, dec, inverst, remain;
printf("enter a decimal number :");
scanf("%d", &dec);
bin = 0;
inverst=1;
while(dec>0)
{
remain = dec%2;
bin = bin + inverst*remain;
inverst = inverst* 10;
dec = dec/2;
}
printf("<bin>=%d
",bin);
getchar();
}
else if ( choices == '2')
{
int m, n, c;
float t;
printf("Compute square root
");
printf("Please input number m: ");
scanf("%d", &m);
printf("Please input square root n times: ");
scanf("%d", &n);
t = 0;
do
{
for (c=1; c<=n; c++)
{
t = sqrt (t + m);
}
printf("t is %2f
", t);
}
while (n<0 || n>5);
getchar();
}
else if ( choices == '3')
{
float a, b, c, delta, x1, x2;
printf("The form of the quadratic equation is ax2 + bx + c = 0
");
printf("Input a = ");
scanf("%f", &a);
printf("Input b = ");
scanf("%f", &b);
printf("Input c = ");
scanf("%f", &c);
if (a==0)
printf("This is not the quadratic equation
Please check again
");
else
{
delta = b*b-4*a*c;
if(delta < 0 )
printf("The equation has no solution
");
else if (delta == 0 )
printf("The solution of the equation is %.2f
", (-b)/(2*a));
else
x1 = (-b - sqrt(delta))/(2*a);
scanf("%f", &x1);
x2 = (-b + sqrt(delta))/(2*a);
scanf("%f", &x2);
printf("The solution of the equation includes
");
printf("x1 = %.2f
", x1);
printf("x2 = %.2f
", x2);
}
getchar();
}
else if (choices == '4')
{
long factorial(int), num;
int A, B, C;
char ch, asc;
do
{
printf("Enter the number of row: ");
scanf("%d", &B);
}
while(B<1 || B>5);
printf("Print a pascal triangle of n rows
");
for(A=0; A<B; A++)
{
for(C=1; C<=B-A; C++)
{
printf(" ");
}
for(C=0;C<=A;C++)
{
num = factorial(A)/(factorial(C)*factorial(A-C));
printf("%ld ", num);
}
printf("
");
}
printf("printf a character triangle
");
for(A=0; A<=B; A++)
{
asc = A+64;
for(C=0; C<=B-A; C++)
{
printf(" ");
}
for(ch='A';ch<=asc; ch++)
{
printf("%C", ch);
}
for(ch=asc-1; ch>='A'; ch--)
{
printf("%C", ch);
}
printf("
");
}
getchar();
}
else if (choices == 'q')
{
exit(0);
}
else
{
printf("You just have 5 options : 1, 2, 3, 4 and q
Check again please
");
}
}View more random threads:
- Làm sao tăng kết nối multipeer connectivity framework ?
- Viết ứng dụng mạng xã hội cần những gì để có thể làm được?
- download link video từ 1 trang web bất kỳ
- Code trong objective c có chạy được trong c++ không
- Cài đặt của cơ chế quản lý bộ nhớ với retain/release/autorelease
- Cách tạo chương trình bản đồ số giống google maps mobile cho iOs?
- Automatic Reference Counting (ARC) trong Xcode 4.2
- Làm sao load 100 cái hình trong IOS
- các pro chỉ em cách chèn file flash đuôi .swf và xcode với!
- @interface và @property có tác dụng gì?
Pallet nhựa Long An đã trở thành một trong những lựa chọn phổ biến cho nhu cầu vận chuyển và lưu trữ hàng hóa trong nhiều ngành công nghiệp. Với đặc tính nhẹ nhàng, chắc chắn và dễ vận chuyển, các...
Thanh lý pallet nhựa Long An giá rẻ