暑假作业c语言41-50

#include<stdio.h>
int fn(int a,int n)
{
     int s;
     while(n>=0)       
        { 
            s=a*n+s; 
            a=a*10; 
            n--; 
        } 
    return s;
}
main()
{
	int a1,n1,i;
	scanf("%d%d",&a1,&n1);
	printf("%d",fn(a1,n1));
}

#include<stdio.h>
int main()
{
	void sort(int a[],int n);
	int i,a[10];
	printf("please input the original array:");
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	sort(a,10);
	for(i=0;i<10;i++)
		printf("%5d",a[i]);
		printf("\n");
	return 0;
}

void sort(int a[],int n)
{
	int min,i,j,t;
	for(i=0;i<n-1;i++)
	{
		min=i;
		for(j=i+1;j<n;j++)
			if(a[min]>a[j])
				min=j;
		t=a[i];a[i]=a[min];a[min]=t;
	}
}

#include <stdio.h>
#include <math.h>
#define S ((a+b+c)/2)
#define AREA sqrt(S*(S-a)*(S-b)*(S-c))
int main()
{
	double a,b,c;
	scanf("%lf %lf %lf",&a,&b,&c);
	printf("%.3lf",AREA);
	return 0;
}

#include<stdio.h>
#define swap(a,b) t=a;a=b;b=t; 
int main()
{
    int x,y,t;
    scanf("%d%d",&x,&y);
    swap(x,y);
    printf("%d %d",x,y);
    return 0;
}

#include<stdio.h>
int digit(int n,int k)
{
    int i,a,count=0,copy_n;
    copy_n=n;
    while(copy_n!=0)
	{
        copy_n/=10;
        count++;
    }
    if(k>count)
	{
        return -1;
    }
    else{
        for(i=1;i<=k;i++)
		{
            a=n%10;
            n/=10;
        }
        return a;
    }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(digit(n,k)==-1)
        printf("k大于数字位数!");
    else
        printf("正整数%d中的第%d位数字为:%d",n,k,digit(n,k));
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <string.h>
int main( )
{
  char a[10];
  void convert(char a[]);
  printf("请输入十六进制数:");
  gets(a);
  convert(a);
  return 0;
}
void convert(char a[])
{
  int n,i,num=0;
  n=strlen(a);
  for(i=n-1;i>=0;i--)
  {
   if(a[i]>='0'&&a[i]<='9')
    num+=(a[i]-'0')*pow(16,n-1-i);
    else if(a[i]>='A'&&a[i]<='F')
        num+=(10+(a[i]-'A'))*pow(16,n-1-i);
     else if(a[i]>='a'&&a[i]<='f')
          num+=(10+(a[i]-'a'))*pow(16,n-1-i);
  }
  printf("转换十进制为:");
  printf("%d",num);
}

#include<stdio.h>
int main()
{ 
	int a[16][16],i=0,j=0,k=0,p=0,n=0;
  	p=1;
  	while(p==1)
    {
		printf("请输入n(0<n<=15,n是奇数):\n");
     	scanf("%d",&n);
     	if ((n>=0) && (n<=15) && (n%2!=0))
       		p=0;
    }
    printf("矩阵阶数是:%d\n",n);
  	for(i=1;i<=n;i++)
  	{
  		for(j=1;j<=n;j++)
    		a[i][j]=0;
    }
    j=n/2+1;
  	a[1][j]=1;
  	for(k=2;k<=n*n;k++)
    {
		i=i-1;
    	j=j+1;
    	if((i<1)&&(j>n))
    	{
			i=i+2;
    		j=j-1;
    	}
     	else
       	{
			if(i<1)
				i=n;
     		if(j>n)
				j=1;
       	}
     	if(a[i][j]==0)
     	{
     		a[i][j]=k;
		}	
     	else
       	{
			i=i+2;
     		j=j-1;
     		a[i][j]=k;
       }
    }
  	for (i=1;i<=n;i++)
  	{	
  		int sum=0;
		for (j=1;j<=n;j++)
		{
			printf("%3d",a[i][j]);
			sum+=a[i][j];
		}	
    	printf("\n");
    }
    printf("\n\n");
  return 0;
}

#include<stdio.h>
#include<string.h>
typedef struct _ballot
{
	char name[8];
	int vote;
}ballot;
void input(ballot can[4]);
void output(ballot can[4]);
int main()
{
	ballot candidate[4]={{"zhao",0},{"qian",0},{"sun",0},{"li",0}};
	input(candidate);
	output(candidate);
	return 0;
}
void input(ballot can[4])
{
	int i,j;
	char name[8];
	printf("input candidators name:\n");
	for(i=0;i<20;i++)
	{
		gets(name);
		for(j=0;j<4;j++)
		{
			if(strcmp(name,can[j].name)==0)
			{
				can[j].vote++;
			}
		}
	}
}
void output(ballot can[4])
{
	int i;
	printf("name \tzhao\tqian\tsun\tli\n");
	printf("tickets\t");
	for(i=0;i<4;i++)
	{
		printf("%d\t",can[i].vote);
	}
	printf("\n");
}

#include"stdio.h"
#define N 1
struct student
{
	char StuID[15];
	char Name[10];
	float Grade[3];
}stu[N];
float Average(struct student stu, int n)
float Average(int n)
int main()
{
	int i,j;
	printf("请输入学生的ID、名字:\n");
	for (i=0;i<N;i++)
	{
		scanf("%s %s", &stu[i].StuID, &stu[i].Name);
		printf("请输入三门课的成绩:");
		for (j=0;j<3;j++)
		{
			scanf("%f", &stu[i].Grade[j]);
		}
	}
	for (i=0;i<N;i++)
	{
		printf("%s %s %f\n",stu[i].StuID,stu[i].Name,Average(3));
	}
	return 0;
}
float Average(int n)
{
	int i,j;
	float sum=0;
	for (i=0;i<N;i++)
	{
		for (j=0;j<n;j++)
		{
			sum=sum+stu[i].Grade[j];
		}
	}
	return sum/n;
}

#include<stdio.h>
struct student
{
  int num;
  float score;
  struct student *next;
};
int main()
{
  struct student a,b,c;
  struct student *head,*point;
  a.num=10101;
  a.score=89.5;
  b.num=10103;
  b.score=90.0;
  c.num=10107;
  c.score=85.0; 
  head=&a;
  a.next=&b;
  b.next=&c;
  c.next=NULL;
  point=head;
  do
  {
    printf("%ld %5.1f\n",point->num,point->score); 
    point=point->next;
  }
  while(point!=NULL);
  return 0;
}

上一篇:2021年上半年信息系统项目管理师上午综合知识真题(41)


下一篇:41.el和template区别 & VUE实现分离写法