-
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:
- IQ Widgets has a Gantt chart. You would need to generate bindings in order to use it in MonoTouch.
- Sự kiện gì sảy ra trong xcode khi kéo các UIButton, UIlabel......
- Ý nghĩa dấu ^ trong objective-c?
- Sử dụng file .PNG làm giao diện phần mềm
- Automatic Reference Counting (ARC) trong Xcode 4.2
- Hiển thị ảnh lên UIScrollview lỗi: Terminating app due to uncaught exception ... was mutated while being enumerated?
- Mọi ngừoi có ai sử dụng thư viện IQ widget trong objective C chưa ạ
- Làm sao load 100 cái hình trong IOS
- Kiểu dữ liệu enum trong object-c?
- Làm sao lấy link url của video/audio từ 1 website cụ thể
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...