在这里放一些初学时在宁波大学OJ写的题,因为太水了所以放到一起,当然对于零基础的人还是有难度的,大神内心默默鄙视就好
单组A+B
#include
int main()
{
int a,b,c;
printf("please input two numbers:\n",a,b);
scanf("%d%d",&a,&b);
c=a+b;
printf("sum is:%d",c);
return 0;
}
#include
int main()
{
int a,b;
scanf("%d%d",&a,&b);
while(a!=0||b!=0)
{
printf("%d\n",a+b);
scanf("%d%d",&a,&b);
}
return 0;
}
#include
int main()
{
int a,b,N;
scanf("%d",&N);
for(;N>0;N--)
{
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
}
三数求平均值
#include
void main()
{
double a,b,c,d;
scanf("%lf%lf%lf",&a,&b,&c);
printf("%.1lf\n",(a+b+c)/3);
}
#include "stdio.h"
void main()
{
double a,b;
scanf("%lf%lf",&a,&b);
printf("%.2lf\n",a+b);
}
#include
void main()
{
double f;
scanf("%lf",&f);
printf("%.2lf\n",5*(f-32)/9);
}
#include
void main()
{
double r;
scanf("%lf",&r);
printf("%.2lf %.2lf\n",2*r*3.14,3.14*r*r);
}
#include
int main()
{
double r,h;
scanf("%lf%lf",&r,&h);
printf("%.2lf\n",(3.14*2*r*h)+(3.14*r*r*2));
}
#include
void main()
{
double r;
scanf("%lf",&r);
printf("%.2lf\n",4.0/3*3.14*r*r*r);
}
#include
#include
void main()
{
double a,b,c,p;
scanf("%lf%lf%lf",&a,&b,&c);
p=(a+b+c)/2;
printf("%.2lf\n",sqrt(p*(p-a)*(p-b)*(p-c)));
}
#include
#include
void main()
{
double a,b,c,p;
scanf("%lf%lf%lf",&a,&b,&c);
p=(a+b+c)/2;
if(a+b>c&&a+c>b&&b+c>a)
printf("%.2lf\n",sqrt(p*(p-a)*(p-b)*(p-c)));
else
printf("Error\n");
}
#include
#include
void main()
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
printf("%.2lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
#include
void main()
{
int m,n;
scanf("%d%d",&m,&n);
printf("%d %d\n",(4*m-n)/2,m-(4*m-n)/2);
}
#include
void main()
{
int x,y;
scanf("%d%d",&x,&y);
printf("%d %d\n",x,y);
printf("%d %d\n",y,x);
}
#include
void main()
{
float x,y;
scanf("%f%f",&x,&y);
printf("%.2f\n",x/y);
}
#include
void main()
{
int x,y;
scanf("%d%d",&x,&y);
printf("%d %d\n",x/y,x%y);
}
#include
void main()
{
int m,n;
scanf("%d%d",&m,&n);
printf("%d %d\n",m/n,m%n);
}
#include
void main()
{
double a;
scanf("%lf",&a);
printf("%.2lf\n",a*6.5573);
}
#include
void main()
{
char ch;
scanf("%c",&ch);
printf("%d\n",ch);
}
成绩预算
#include
void main()
{
char ch;
scanf("%c",&ch);
printf("%c\n",ch-32);
}
#include
void main()
{
char ch1,ch2;
scanf("%c%c",&ch1,&ch2);
printf("%c%c\n",ch1+3,ch2+3);
}
#include
void main()
{
char aa,bb,cc;
scanf("%c%c%c",&aa,&bb,&cc);
if(aa=='+')
printf("%d\n",bb+cc);
else
printf("%d\n",bb-cc);
}
#include
void main()
{
double x,y;
scanf("%lf",&x);
y=2*x*x+x+8;
printf("%.1lf\n",y);
}
#include
void main()
{
double x,y;
scanf("%lf",&x);
y=3*x*x*x*x-2*x*x*x-x*x+10;
printf("%.1lf\n",y);
}
#include
void main()
{
double x,y;
scanf("%lf%lf",&x,&y);
printf("%.2lf\n",0.538*x+0.03*y);
}
#include
#include
void main()
{
double money,year,rate;
scanf("%lf%lf%lf",&money,&year,&rate);
printf("%.2lf\n",money*pow(1+rate,year)-money);
}
#include
void main()
{
double i,s;
scanf("%lf%lf",&i,&s);
printf("%.2lf\n",s*(1+i));
}
三位数的数位分离
#include
void main()
{
int x;
scanf("%d",&x);
printf("%d %d %d\n",x%10,x%100/10,x/100);
}
#include
void main()
{
int n,m,i;
unsigned __int64 sum;
scanf("%d",&n);
i=1;
sum=0;
for(m=1;m<=n;m=m+1)
{
sum=sum+i;
i=2*i;
}
printf("%I64u\n", sum);
}
#include
void main()
{
int x;
scanf("%d",&x);
while(x%10==0)
{
x=x/10;
}
while(x!=0)
{
printf("%d",x%10);
x=x/10;
}
printf("\n");
}
#include
void main()
{
int x,i,z=0;
scanf("%d",&x);
while(x!=0)
{
i=x%10;
z=z+i;
x=x/10;
}
printf("%d\n",z);
}
#include
void main()
{
int x;
scanf("%d",&x);
while(x/10)
x/=10;
printf("%d\n",x);
}
#include
#include
void main()
{
char x[1000];
int y,i,sum=0;
gets(x);
y=strlen(x);
for(i=0;i<=y;i++)
{
if(x[i]>='0'&&x[i]<='9')
sum++;
}
printf("%d\n",sum);
}
#include
void main()
{
int x;
scanf("%d",&x);
if(x>=0)
printf("%d\n",x);
else
printf("%d\n",-x);
}
#include
void main()
{
float x;
scanf("%f",&x);
if(x>0)
printf("1\n");
else
{if(x<0)
printf("-1\n");
else
printf("0\n");}
}
#include
void main()
{
int x;
scanf("%d",&x);
if(x>0)
printf("positive\n");
else
printf("negative\n");
}
#include
void main()
{
int x;
scanf("%d",&x);
if(x%2==0)
printf("even\n");
else
printf("odd\n");
}
#include
void main()
{
int x,i=1,sum1=0,sum2=0;
scanf("%d",&x);
if(x%2==0)
{printf("%d\n",(x/2)*(1+x-1)/2);
printf("%d\n",(x/2)*(2+x)/2);}
else
{printf("%d\n",(((x+1)/2)*(1+x))/2);
printf("%d\n",(((x-1)/2)*(2+x-1))/2);}
}
#include
void main()
{
int x,i,y,sum1=0,sum2=0;
scanf("%d",&x);
for(i=0;i
#include
void main()
{
int x;
scanf("%d",&x);
if(1<=x&&x<10)
printf("%d\n",3*x-1);
else
{
if(x<1)
printf("%d\n",x);
else
printf("%d\n",4*x-2);
}
}
分段函数2
#include
#include
void main()
{
int x;
scanf("%d",&x);
if(x>=0)
printf("%.2lf\n",x*x-2.0);
else
printf("%.2lf\n",sqrt(5-x));
}
分段函数3
#include
#include
void main()
{
double x;
scanf("%lf",&x);
if(x<0)
printf("%.2lf\n",(pow(x+1,2)+2*x+1/x));
else
printf("%.2lf\n",sqrt(x));
}
#include
void main()
{
int x,y;
scanf("%d%d",&x,&y);
if(x>0)
{
if(y>0)
printf("1\n");
else
printf("4\n");
}
else
{
if(y>0)
printf("2\n");
else
printf("3\n");
}
}
#include
#include
void main()
{
int x,y;
double a;
scanf("%d%d",&x,&y);
a=sqrt(x*x+y*y);
if(a<10)
printf("in\n");
else if(a==10)
printf("on\n");
else
printf("out\n");
}
#include
void main()
{
char x;
scanf("%c",&x);
if(x>='A'&&x<='Z'||x>='a'&&x<='z')
printf("YES\n");
else
printf("NO\n");
}
#include
void main()
{
char x;
scanf("%c",&x);
if(x>='A'&&x<='Z')
{
x=x+32;
}
else if(x>='a'&&x<='z')
{
x=x-32;
}
printf("%c\n",x);
}
#include
void main()
{
int x;
scanf("%d",&x);
if(x>='a'&&x<='z'||x>='A'&&x<='Z')
printf("%c\n",x);
else
printf("%d\n",x);
}
#include
void main()
{
char x;
scanf("%c",&x);
if(x>'A'&&x<'Z')
printf("upper\n");
else
{
if(x>'a'&&x<'z')
printf("lower\n");
else
{
if(x>'0'&&x<'9')
printf("digit\n");
else
printf("other\n");
}
}
}
#include
#include
void main()
{
char x[123123];
int y;
gets(x);
y=strlen(x);
printf("%d\n",y);
}