-
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ấy khoảng cách từ (camera)iphone xuống mặt đất, sử dụng GPS và CLLocationManager.
- So sánh điểm giống và khác nhau giữa Objective c và c/c++
- Khai báo hàm
- Hiển thị ảnh lên UIScrollview lỗi: Terminating app due to uncaught exception ... was mutated while being enumerated?
- Sử dụng dispatch_block_t với disable ARC
- Objective C: alloc và Release ngay khi nó vẫn được sử dụng không bị lỗi, nghĩa là thế nào?
- Chơi một phần của Audio trong iOS
- Cơ chế truyền delegate trong Objective C như thế nào ???
- download link video từ 1 trang web bất kỳ
- Viết ứng dụng mạng xã hội cần những gì để có thể làm được?
Ngoại trừ một số ít trường hợp rãnh mũi - má và “râu rồng silicon” xuất hiện sớm, có khi từ tuổi thanh niên do cơ địa, còn lại, đại đa số do căn do lão hoá đã gây nên ba diễn biến: Giảm mô xương gò...
Cách thẩm mỹ má ở tuổi trung niên...