1. Enter a, b, c of three values, wherein the maximum of the output
#include <stdio.h>
int f(int a,int b,int c)
{
int m;
if(a>b)
m=a;
else
m=b;
if(c>m)
m=c;
return m;
}
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%d\n",f(a,b,c));
return 0;
}
operation result:
2. seek 5!
#include <stdio.h>
int main()
{
int i,t=1;
for(i=2; i<=5; i++)
t=t*i;
printf("5!=%d",t);
return 0;
}
operation result:
3 + ... find polynomial 1-1 / 2 + 1 / 3-1 / 4 + 1 / 99-1 / 100
#include <stdio.h>
int main()
{
int i,sign=1;
double sum=1.0,term;
for(i=2; i<=100; i++)
{
sign=-sign;
term=1.0/i;
sum+=term;
}
printf("%lf\n",sum);
return 0;
}
operation result:
4. The area of the triangle seek
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,s,area;
scanf("%lf %lf %lf",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("a=%.2lf\tb=%.2lf\tc=%.2lf\n",a,b,c);
printf("area=%.2lf\n",area);
return 0;
}
operation result:
The root seeking a * x² + b * x + c = 0 Equation. a, b, c by a keyboard input, provided b²-4 * a * c> 0
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,disc,x1,x2,p,q;
scanf("%lf %lf %lf",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2.0*a);
q=sqrt(disc)/(2.0*a);
x1=p+q;
x2=p-q;
printf("x1=%.2lf\nx2=%.2lf\n",x1,x2);
return 0;
}
operation result:
6. Use π / 4≈1-1 / 3 + 1 / 5-1 / 7 + ... to approximate formula of [pi], until it finds an absolute value of less than one up to six degrees is 10 (without the accumulation )
#include <stdio.h>
#include <math.h>
int main()
{
int sign=1;
double pi=0.0,n=1.0,term=1.0;
while(fabs(term)>=1e-6)
{
pi+=term;
n=n+2;
sign=-sign;
term=sign/n;
}
pi=pi*4;
printf("pi≈%.8lf\n",pi);
return 0;
}
operation result:
7. 40 before seek Fibinacci number sequence. (One pair of rabbits from the first 3 months after birth are born every month one pair of rabbits, bunnies grow up to the third month gave birth to a pair of rabbits do not assume that all the dead, asked the total number of rabbits per month how many?)
#include <stdio.h>
int main()
{
int fi[20]= {1,1};
for(int i=2; i<20; i++)
fi[i]=fi[i-1]+fi[i-2];
for(int i=0; i<20; i++)
{
if(i%5==0)
printf("\n");
printf("%12d",fi[i]);
}
printf("\n");
return 0;
}
operation result:
8. Enter a number, it is determined whether or not a prime number
#include <stdio.h>
#include <math.h>
int main()
{
int n,flag=1;
scanf("%d",&n);
for(int i=2; i<=sqrt(n); i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag)
printf("%d is prime!\n",n);
else
printf("%d is not prime!\n",n);
return 0;
}
operation result:
9. Finding all prime numbers between 100 and 200
#include <stdio.h>
#include <math.h>
int isPrime(int n) //判断是否为素数
{
for(int i=2; i<=sqrt(n); i++)
{
if(n%i==0)
return 0;
}
return 1;
}
int main()
{
for(int i=100; i<=200; i++)
{
if(isPrime(i))
printf("%d\n",i);
}
return 0;
}
operation result:
10. Translation password A-> E, a-> e, i.e. the subsequent letters are converted to four letters
W->A,X->B,Y->C,Z->D,
Non-alphabetic maintain the status quo unchanged
For example: "China" -> "Glmre"
#include <stdio.h>
int main()
{
char c;
while((c=getchar())!='\n')
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c+4;
if((c>'Z'&&c<'Z'+4)||c>'z')
c=c-26;
}
printf("%c",c);
}
printf("\n");
return 0;
}
operation result: