-
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:
- Cài đặt của cơ chế quản lý bộ nhớ với retain/release/autorelease
- Block trong objective c
- Mfc c++
- Lỗi "exc_bad_access" trong xcode
- Tạo ảnh trong textview Iphone như thế nào?
- Làm sao hẹn giờ chơi nhạc
- UITabbarcontroller scroll, có thể cho phép UITabbarcontroller kéo đi được không?
- Lập trình Objectice C - Cùng trao đổi kinh nghiệm về lập trình IOS
- Làm cách nào cài máy ảo MAC + Xcode để lập trình Iphone Trên Windows
- How can I create gantt Chart in IOS objective C
Trứng rung điều khiển từ xa Vibrator Spark Of Love Sản phẩm trứng rung bluetooth có điều khiển từ xa này được thiết kế với tông màu Rose Gold viền kim khí trải qua. kích tấc 7,4cm x 3,5cm giúp trứng...
TOP 3 trùy rung điều khiển từ xa...