在这里放一些初学时在宁波大学OJ写的题,因为太水了所以放到一起,当然对于零基础的人还是有难度的,大神内心默默鄙视就好
单组A+B
#include<stdio.h> 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<stdio.h> 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<stdio.h> int main() { int a,b,N; scanf("%d",&N); for(;N>0;N--) { scanf("%d%d",&a,&b); printf("%d\n",a+b); } }
三数求平均值
#include<stdio.h> 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<stdio.h> void main() { double f; scanf("%lf",&f); printf("%.2lf\n",5*(f-32)/9); }
#include<stdio.h> void main() { double r; scanf("%lf",&r); printf("%.2lf %.2lf\n",2*r*3.14,3.14*r*r); }
#include<stdio.h> int main() { double r,h; scanf("%lf%lf",&r,&h); printf("%.2lf\n",(3.14*2*r*h)+(3.14*r*r*2)); }
#include<stdio.h> void main() { double r; scanf("%lf",&r); printf("%.2lf\n",4.0/3*3.14*r*r*r); }
#include<stdio.h> #include<math.h> 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<stdio.h> #include<math.h> 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<stdio.h> #include<math.h> 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<stdio.h> void main() { int m,n; scanf("%d%d",&m,&n); printf("%d %d\n",(4*m-n)/2,m-(4*m-n)/2); }
#include<stdio.h> void main() { int x,y; scanf("%d%d",&x,&y); printf("%d %d\n",x,y); printf("%d %d\n",y,x); }
#include<stdio.h> void main() { float x,y; scanf("%f%f",&x,&y); printf("%.2f\n",x/y); }
#include<stdio.h> void main() { int x,y; scanf("%d%d",&x,&y); printf("%d %d\n",x/y,x%y); }
#include<stdio.h> void main() { int m,n; scanf("%d%d",&m,&n); printf("%d %d\n",m/n,m%n); }
#include<stdio.h> void main() { double a; scanf("%lf",&a); printf("%.2lf\n",a*6.5573); }
#include<stdio.h> void main() { char ch; scanf("%c",&ch); printf("%d\n",ch); }
成绩预算
#include <stdio.h> void main() { char ch; scanf("%c",&ch); printf("%c\n",ch-32); }
#include<stdio.h> void main() { char ch1,ch2; scanf("%c%c",&ch1,&ch2); printf("%c%c\n",ch1+3,ch2+3); }
#include <stdio.h> 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<stdio.h> void main() { double x,y; scanf("%lf",&x); y=2*x*x+x+8; printf("%.1lf\n",y); }
#include<stdio.h> 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<stdio.h> void main() { double x,y; scanf("%lf%lf",&x,&y); printf("%.2lf\n",0.538*x+0.03*y); }
#include <stdio.h> #include<math.h> void main() { double money,year,rate; scanf("%lf%lf%lf",&money,&year,&rate); printf("%.2lf\n",money*pow(1+rate,year)-money); }
#include<stdio.h> void main() { double i,s; scanf("%lf%lf",&i,&s); printf("%.2lf\n",s*(1+i)); }
三位数的数位分离
#include <stdio.h> void main() { int x; scanf("%d",&x); printf("%d %d %d\n",x%10,x%100/10,x/100); }
#include<stdio.h> 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<stdio.h> 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<stdio.h> 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 <stdio.h> void main() { int x; scanf("%d",&x); while(x/10) x/=10; printf("%d\n",x); }
#include<stdio.h> #include <string.h> 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<stdio.h> void main() { int x; scanf("%d",&x); if(x>=0) printf("%d\n",x); else printf("%d\n",-x); }
#include<stdio.h> 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 <stdio.h> void main() { int x; scanf("%d",&x); if(x>0) printf("positive\n"); else printf("negative\n"); }
#include<stdio.h> void main() { int x; scanf("%d",&x); if(x%2==0) printf("even\n"); else printf("odd\n"); }
#include <stdio.h> 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<stdio.h> void main() { int x,i,y,sum1=0,sum2=0; scanf("%d",&x); for(i=0;i<x;i++) { scanf("%d",&y); if(y%2==0) sum1=sum1+y; else sum2=sum2+y; } printf("%d\n%d\n",sum2,sum1); }
#include<stdio.h> 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<stdio.h> #include<math.h> 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<stdio.h> #include<math.h> 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<stdio.h> 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 <stdio.h> #include <math.h> 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<stdio.h> void main() { char x; scanf("%c",&x); if(x>='A'&&x<='Z'||x>='a'&&x<='z') printf("YES\n"); else printf("NO\n"); }
#include <stdio.h> 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 <stdio.h> 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<stdio.h> 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 <stdio.h> #include<string.h> void main() { char x[123123]; int y; gets(x); y=strlen(x); printf("%d\n",y); }