
#include<stdio.h>
int main(){
printf("hello world");
return 0;
}
#include<stdio.h>
int main(){
int inch,cun;
float meter;
scanf("%d,%d",&inch,&cun);
meter=inch*0.3048+cun*0.0254;
printf("The meter is %f\n",meter);
}cun的除数12先同0.3048相乘,再与inch计算的结果相加。printf函数的数据类型要统一
#include<stdio.h>
int main(){
char char_x, m, n, a, A;
a = 97;A = 65;
printf("Please enter a character:");
scanf("%c",&char_x);
if((char_x >= 'a'&&char_x <= 'm')){
// n=char_x-a;
m = char_x + char_x - a + 1;
// printf("%c",m);
}
if(char_x >= 'A'&&char_x <= 'M'){
// n=char_x-A;
m = char_x + char_x - A + 1;
// printf("%c",m);
}
if(char_x>'M'&&char_x<='Z'){
m = char_x + char_x - A- 25;
// printf("%c",m);
// 在这里,由于字母表是闭环,所以超过一圈时要减掉一周的量
}
if(char_x > 'm'&&char_x <= 'z'){
m = char_x+char_x-a-25;
// printf("%c",m);
}
printf("%c",m);
return 0;
}
#include<stdio.h>
#include<math.h>
int main(){
int n, i, j, k = 1,a[1000];
printf("pelase enter a number:\n");
scanf("%d",&n);
printf("2 is a prime number.\n");
for(i = 2;i <= n; i++){
for(j = 2;j <= i; j++)
{
if(i%j == 0)break;
if(j >= sqrt(i)&&j < sqrt(i) + 1){printf("%d is a prime number.\n",i);
k++;}
}
}
printf("there are %d prime numbers!",k);
return 0;
}
#include<stdio.h>
#include<math.h>
int main(){
double y;
int xx,xs,xc;
for(y=1;y>=-1;y-=0.1){
xc=acos(y)*10;
xs=asin(y)*10;
if(xs<0){
xs=-xs+31;
}
for(xx=0;xx<=62;xx++){
if(xx==xs||xx==31-xs||xx==93-xs){
printf("*");
}
else if(xx==xc||xx==62-xc){
printf("*");
}
else{
printf(" ");
}
}
printf("\n");
}
return 0;
}*,不在的为空格
#include<stdio.h>
int count(int s);
int main(){
int m , d, i = 0,n = 1,t = 0, s, output;
do{
scanf("%d/%d",&m,&d);
if(m>8||m<7||n<=0||n>31)return 0;
s = (m-7)*31+d;
output = count(s);
printf("%d\n",output);
}
while(m != 0&&d != 0);
}
int count(int s){
int a[10] = {1,3,6,10,15,21,28,36,45,55};
int n = 1, t = 0;
for(int i = 0;i < 10;i++){
if(a[i] >= s) t++;
}
return(t);
}date转化为十进制的数来表示,然后再统计停电的日期
#include<stdio.h>
int main(){
int M,N,T,t,test;
scanf("%d",&T);
for(test=1;test<=T;++test){
scanf("%d %d",&M,&N);
int res[4][4]={{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}};
int A[4][4];
int i,j,t,k;
for(i=0;i<M;i++){
for(j=0;j<M;j++){
scanf("%d",&A[i][j]);
}
}
for(t=0;t<N;++t){
int tmp[4][4]={0};
for(i=0;i<M;++i){
for(j=0;j<M;++j){
for(k=0;k<M;++k){
tmp[i][j]+=res[i][k]*A[k][j];
}
}
}
for(i=0;i<M;i++){
for(j=0;j<M;j++){
res[i][j]=tmp[i][j];
}
}
}
printf("Case %d:\n",test);
for(i=0;i<M;i++){
for(j=0;j<M;j++){
printf("%d",res[i][j]);
if(j!=M-1)printf(" ");
}
printf("\n");
}
}
return 0;
}流程图

这题的难点在于手写一个矩阵的乘法运算

#include<stdio.h>
int main()
{
int N,value,row,col,dir,i,j, n;
while(scanf("%d",&N)!=EOF)
{
int tri[24][24]={0};
row = col = 1;
value = 1;
for(;value<=N;++value)
tri[row++][col]=value;
row = N;
col =2 ;
value = N+1;
for(;value<=2*N-1;++value)
tri[row][col++] = value;
row = N-1;
col = N-1;
value = 2*N;
for(;value<=3*N-3;++value)
tri[row--][col--] = value;
row = 2;
col = 2;
value = 3*N-2;
dir = 1;
while(value<=N*(N+1)/2)
{
if(1==dir)
{
if((0==tri[row+1][col]))
tri[++row][col] = value;
else
{
dir = 2;
tri[row][++col] = value;
}
}
else if(2==dir)
{
if((0==tri[row][col+1]))
tri[row][++col] = value;
else
{
dir = 3;
tri[--row][--col] = value;
}
}
else
{
if((0==tri[row-1][col-1]))
tri[--row][--col] = value;
else
{
dir=1;
tri[++row][col] = value;
}
}
++value;
}
row = 1;
for(;row<=N;++row)
{
col = 1;
for(;col<=row;++col)
{
printf("%d",tri[row][col]);
if(!(row==N&&col==row))
{printf(" ");}
tri[row][col] = 0;
}
}
printf("\n");
}
return 0;
}
选择+判断即可完成实验九

#include<stdio.h>
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int l = n;
for (int m = 1; m <= l; m++) {
int i = m;
while (i > 0) {
int j = i % 10;
i = i / 10;
if (j == 1 || j == 5) {
n = n - 1;
break;
}
}
}
printf("%d\n", n);
}
}1 or 5直接break,时间复杂度为 O(n·log(n))实验九(二)

#include<stdio.h>
#include<math.h>
int main(){
double f2(int n , double a[] , double x);
int n;
while(scanf("%d",&n)!=EOF){
double num[10000];
for(int i = 0;i <= n;++i){
scanf("%lf",num+i);
}
int m;
scanf("%d",&m);
double ans[1000];
for(int j = 0;j < m;++j){
double x;
scanf("%lf",x);
ans[j] = f2(n+1,num,x);
}
for(int j = 0;j < m;++j){
printf("%lf",ans[j]);
if(j!=m-1)printf(" ");
}
printf("\n");
}
}
double f2(int n , double a[] , double x){
int i;
double p = a[0];
for(i = 1;i < n ;i++){
p += (a[i] * pow(x,i));
}
return p;
} 实验十一

#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct medol
{
char name[21];
int jin;
int yin;
int tong;
struct medol *next;
};
struct medol *myhead = NULL;
void printdata();
int my_sort(char *name, int ji, int yi, int to, int len){
int i=0;
struct medol *p=NULL, *q=NULL, *tmp=NULL;
if(myhead == NULL)
return -1;
if(len == 0)
{
myhead->next = (struct medol*)malloc(sizeof(struct medol));
if(myhead->next != NULL)
{
memcpy(myhead->next->name, name, 21);
myhead->next->jin = ji;
myhead->next->yin = yi;
myhead->next->tong = to;
myhead->next->next = NULL;
}
else
{
return -1;
}
}
else
{
if(myhead->next == NULL)
return -1;
p = myhead->next;
tmp = (struct medol*)malloc(sizeof(struct medol));
if(tmp != NULL)
{
memcpy(tmp->name, name, 21);
tmp->jin = ji;
tmp->yin = yi;
tmp->tong = to;
tmp->next = NULL;
}
else
return -1;
for(i=0; i< len+1; i++)
{
if(p != NULL)
{
if(ji > p->jin
|| (ji == p->jin && yi > p->yin)
|| (ji == p->jin && yi == p->yin && to > p->tong)
|| (ji == p->jin && yi == p->yin && to == p->tong && strcmp(name, p->name) < 0)
)
{
if(p == myhead->next)
{
tmp->next = p;
myhead->next = tmp;
}
else
{
tmp->next = p;
q->next = tmp;
}
break;
}
else
{
q = p;
p = p->next;
}
}
else
{
q->next = tmp;
break;
}
}
}
return 0;
}
void printdata()
{
struct medol *p=NULL;
if(myhead == NULL)
return;
p = myhead->next;
while(p)
{
printf("%s\n", p->name);
p = p->next;
}
}
void freedata()
{
struct medol *p=NULL, *q=NULL;
if(myhead == NULL)
return;
p=q=myhead->next;
while(p)
{
q = p->next;
free(p);
p = NULL;
p = q;
}
free(myhead);
myhead = NULL;
}
int main()
{
int country_num = 0;
char c_name[21]={0};
int tmj=0, tmy=0, tmt=0;
int i=0;
scanf("%d", &country_num);
if(country_num > 0 && country_num < 21)
{
myhead = (struct medol*)malloc(sizeof(struct medol));
if(myhead == NULL)
return 1;
myhead->next = NULL;
for(i=0; i<country_num; i++)
{
scanf("%s %d %d %d", c_name, &tmj, &tmy, &tmt);
my_sort(c_name, tmj, tmy, tmt, i);
}
printdata();
freedata();
}
return 0;
}实验十二

- 目前没有好的思路