-
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:
- PopviewController quay về viewController trước đó
- Phép chia lấy phần dư của một số thập phân cho số nguyên. Lỗi invalid operands of types `double' and `int' to binary
- Cách dùng TableView trong iOS như thế nào?
- Mọi người định hướng giúp cái bài hướng đối tượng này với !!!
- Xây dựng chương trình Quản lý điểm học sinh bằng IOS
- Hiển thị ảnh lên UIScrollview lỗi: Terminating app due to uncaught exception ... was mutated while being enumerated?
- Chơi một phần của Audio trong iOS
- Lấy khoảng cách từ (camera)iphone xuống mặt đất, sử dụng GPS và CLLocationManager.
- Làm cách nào cài máy ảo MAC + Xcode để lập trình Iphone Trên Windows
- Làm thế nào để tạo một thư viện (.dylib) dùng cho iOS dựa trên code c/c++ từ các thư viện open-source, môi trường Xcode 5.x
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...