matlab绘图如何添加图例坐标轴刻度

matlab绘图如何添加图例坐标轴刻度,第1张

1、首先打开电脑上的“matlab”软件,主界面如下图所示,箭头处输入代码即可运行。

2、下面输入代码绘制图像,命令行代码如下图所示。

3、点击enter键之后,即可运行程序绘制图像,正弦函数图像,可以看到x和y的坐标轴刻度。

4、下面使用set(gca,'XTick',0:pi/2:2pi);set(gca,'XTicklabel',{'0','pi/2','pi','3pi/2','2pi'})命令,调整x坐标轴的刻度,间隔为pi/2。

5、最后点击enter键之后,程序运行结果如下图所示,x轴的坐标轴刻度发生了变化。

1.5请参照本章例题,编写一个C程序,输出以下信息:

Very Goodj!

解:

main()

{

printf(" \n");

printf("\n");

printf(" Very Good! \n");

printf("\n");

printf(" \n");

}

16编写一个程序,输入a b c三个值,输出其中最大者。

解:main()

{int a,b,c,max;

printf("请输入三个数a,b,c:\n");

scanf("%d,%d,%d",&a,&b,&c);

max=a;

if(max<b)

max=b;

if(max<c)

max=c;

printf("最大数为:%d",max);

}

第三章

33 请将下面各数用八进制数和十六进制数表示:

(1)10 (2)32 (3)75 (4)-617

(5)-111 (6)2483 (7)-28654 (8)21003

解:十 八 十六

(10)=(12)=(a)

(32)=(40)=20

(75)=(113)=4b

(-617)=(176627)=fd97

-111=177621=ff91

2483=4663=963

-28654=110022=9012

21003=51013=520b

35字符常量与字符串常量有什么区别?

解:字符常量是一个字符,用单引号括起来。字符串常量是由0个或若干个字符

而成,用双引号把它们括起来,存储时自动在字符串最后加一个结束符号'\0'

36写出以下程序的运行结果:

#include<stdioh>

void main()

{

char c1='a',c2='b',c3='c',c4='\101',c5='\116';

printf("a%c b%c\tc%c\tabc\n",c1,c2,c3);

printf("\t\b%c %c\n",c4,c5);

解:程序的运行结果为:

aabb cc abc

A N

37将"China"译成密码密码规律:用原来的字母后面第4个字母代替原来的字母,

例如,字母"A"后面第4个字母是"E",用"E"代替"A"因此,"China"应译为"Glmre"

请编一程序,用赋初值的议程使c1,c2,c3,c4,c5分别变成'G','1','m','r','e',并

输出

main()

{char c1="C",c2="h",c3="i",c4='n',c5='a';

c1+=4;

c2+=4;

c3+=4;

c4+=4;

c5+=4;

printf("密码是%c%c%c%c%c\n",c1,c2,c3,c4,c5);

}

38例36能否改成如下:

#include<stdioh>

void main()

{

int c1,c2;(原为 char c1,c2)

c1=97;

c2=98;

printf("%c%c\n",c1,c2);

printf("%d%d\n",c1,c2);

}

解:可以因为在可输出的字符范围内,用整型和字符型作用相同

39求下面算术表达式的值

(1)x+a%3(int)(x+y)%2/4=25(x=25,a=7,y=47)

(2)(float)(a+b)/2+(int)x%(int)y=35(设a=2,b=3,x=35,y=25)

310写出下面程序的运行结果:

#include<stdioh>

void main()

{

int i,j,m,n;

i=8;

j=10;

m=++i;

n=j++;

printf("%d,%d,%d,%d\n",i,j,m,n);

}

解:结果: 9,11,9,10

第4章

44a=3,b=4,c=5,x=12,y=24,z=-36,u=51274,n=128765,c1='a',c2='b'想得

到以下的输出格式和结果,请写出程序要求输出的结果如下:

a= 3 b= 4 c= 5

x=1200000,y=2400000,z=-3600000

x+y= 360 y+z=-120 z+x=-240

u= 51274 n= 128765

c1='a' or 97(ASCII)

c2='B' or 98(ASCII)

解:

main()

{

int a,b,c;

long int u,n;

float x,y,z;

char c1,c2;

a=3;b=4;c=5;

x=12;y=24;z=-36;

u=51274;n=128765;

c1='a';c2='b';

printf("\n");

printf("a=%2d b=%2d c=%2d\n",a,b,c);

printf("x=%86f,y=%86f,z=%96f\n",x,y,z);

printf("x+y=%52f y=z=%52f z+x=%52f\n",x+y,y+z,z+x);

printf("u=%6ld n=%9ld\n",u,n);

printf("c1='%c' or %d(ASCII)\n",c1,c2);

printf("c2='%c' or %d(ASCII)\n",c2,c2);

}

45请写出下面程序的输出结果

结果:

57

5 7

67856400,-789123962

67856400 ,-789123962

6786,-78912,67856400,-789123962,67856400,-789123962

6785640e+001,-789e+002

A,65,101,41

1234567,4553207,d687

65535,17777,ffff,-1

COMPUTER, COM

46用下面的scanf函数输入数据,使a=3,b=7,x=85,y=7182,c1='A',c2='a',

问在键盘上如何输入

main()

{

int a,b;

float x,y;

char c1,c2;

scanf("a=%d b=%d,&a,&b);

scanf(" x=%f y=%e",&x,&y);

scanf(" c1=%c c2=%c",&c1,&c2);

}

解:可按如下方式在键盘上输入:

a=3 b=7

x=85 y=7182

c1=A c2=a

说明:在边疆使用一个或多个scnaf函数时,第一个输入行末尾输入的"回车"被第二

个scanf函数吸收,因此在第二\三个scanf函数的双引号后设一个空格以抵消上行

入的"回车"如果没有这个空格,按上面输入数据会出错,读者目前对此只留有一

初步概念即可,以后再进一步深入理解

47用下面的scanf函数输入数据使a=10,b=20,c1='A',c2='a',x=15,y=-375,z=578,请问

在键盘上如何输入数据?

scanf("%5d%5d%c%c%f%f%f %f",&a,&b,&c1,&c2,&y,&z);

解:

main()

{

int a,b;

float x,y,z;

char c1,c2;

scanf("%5d%5d%c%c%f%f",&a,&b,&c1,&c2,&x,&y,&z);

}

运行时输入:

10 20Aa15 -375 +15,678

注解:按%5d格式的要求输入a与b时,要先键入三个空格,而后再打入10与20。%f是用来禁止赋值的。在输入时,对应于%f的地方,随意打入了一个数15,该值不会赋给任何变量。

38设圆半径r=15,圆柱高h=3,求圆周长,圆面积,圆球表面积,圆球体积,圆柱体积,用scanf输入数据,输出计算结果,输出时要求有文字说明,取小数点后两位数字请编程

解:main()

{

float pi,h,r,l,s,sq,vq,vz;

pi=31415926;

printf("请输入圆半径r圆柱高h:\n");

scanf("%f,%f",&r,&h);

l=2pir;

s=rrpi;

sq=4pirr;

vq=40/30pirrr;

vz=pirrh;

printf("圆周长为: =%62f\n",l);

printf("圆面积为: =%62f\n",s);

printf("圆球表面积为: =%62f\n",sq);

printf("圆球体积为: =%62f\n",vz);

}

49输入一个华氏温度,要求输出摄氏温度,公式为C=5/9(F-32),输出要有文字说明,取两位小数

解: main()

{

float c,f;

printf("请输入一个华氏温度:\n");

scanf("%f",&f);

c=(50/90)(f-32);

printf("摄氏温度为:%52f\n",c);

}

第五章 逻辑运算和判断选取结构

54有三个整数a,b,c,由键盘输入,输出其中最大的数

main()

{

int a,b,c;

printf("请输入三个数:");

scanf("%d,%d,%d",&a,&b,&c);

if(a<b)

if(b<c)

printf("max=%d\n",c);

else

printf("max=%d\n",b);

else if(a<c)

printf("max=%d\n",c);

else

printf("max-%d\n",a);

}

方法2:使用条件表达式

main()

{int a,b,c,termp,max;

printf(" 请输入 A,B,C: ");

scanf("%d,%d,%d",&a,&b,&c);

printf("A=%d,B=%d,C=%d\n",a,b,c);

temp=(a>b)a:b;

max=(temp>c) temp:c;

printf(" A,B,C中最大数是%d,",max);

}

55 main()

{int x,y;

printf("输入x:");

scanf("%d",&x);

if(x<1)

{y=x;

printf("X-%d,Y=X=%d \n",x,y);

}

else if(x<10)

{y=2x-1;

printf(" X=%d, Y=2X-1=%d\n",x,y);

}

else

{y=3x-11;

printf("X=5d, Y=3x-11=%d \n",x,y);

}

}

57给一个不多于5位的正整数,要求:1求它是几位数2分别打印出每一位数字3按逆序打印出各位数字例如原数为321,应输出123

main()

{

long int num;

int indiv,ten,hundred,housand,tenthousand,place;

printf("请输入一个整数(0-99999):");

scanf("%ld",&num);

if(num>9999)

place=5;

else if(num>999)

place=4;

else if(num>99)

place=3;

else if(num>9)

place=2;

else place=1;

printf("place=%d\n",place);

printf("每位数字为:");

ten_thousand=num/10000;

thousand=(num-tenthousand10000)/1000;

hundred=(num-tenthousand10000-thousand1000)/100;

ten=(num-tenthousand10000-thousand1000-hundred100)/10;

indiv=num-tenthousand10000-thousand1000-hundred100-ten10;

switch(place)

{case 5:printf("%d,%d,%d,%d,%d",tenthousand,thousand,hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,tenthousand);

break;

case 4:printf("%d,%d,%d,%d",thousand,hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d%d\n",indiv,ten,hundred,thousand);

break;

case 3:printf("%d,%d,%d\n",hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d\n",indiv,ten,hundred);

case 2:printf("%d,%d\n",ten,indiv);

printf("\n反序数字为:");

printf("%d%d\n",indiv,ten);

case 1:printf("%d\n",indiv);

printf("\n反序数字为:");

printf("%d\n",indiv);

}

}

58 1if语句

main()

{long i;

float bonus,bon1,bon2,bon4,bon6,bon10;

/初始化变量/

bon1=10000001;

bon2=1000000075+bon1;

bon4=200000005+bon2;

bon6=200000003+bon4;

bon10=4000000015+bon6;

printf("请输入利润");

scanf("%ld",&i);

/计算/

if(i<=le5)

bonus=i01;

else if(i<2e5)

bonus=bon1+(1-100000)0075;

else if(i<=4e5)

bonus=bon2+(i-200000)005;

else if(i<=6e5)

bonus=bon4+(i-400000)003;

else if(i<=le6)

bonus=bon6+(i-600000)0015;

else

bonus=bon10+(i-1000000)001;

printf("奖金是 %102f",bonus);

}

用switch语句编程序

main()

{long i;

float bonus,bon1,bon2,bon4,bon6,bon10;

int branch;

/初始化变量/

bon1=10000001;

bon2=bon1+1000000075

bon4=bon2+200000005;

bon6=bon4+200000003;

bon10=bon6+4000000015;

printf("请输入利润:");

scanf("%ld",&i);

branch=i/100000;

if(branch>10)

branch=10;

/计算/

switch(branch)

{case 0:bonus=i01;break;

case 1:bonus=bon1+(i-100000)0075;break;

case 2:

case 3:bonus=bon2+(i-200000)005;break;

case 4:

case 5:bonus=bon4+(i-400000)003;break;

case 6:

case 7:

case 8:

case 9:bonus=bon6+(i-600000)0015;break;

case 10:bonus=bon10+(i-1000000)001;

}

printf(" 奖金是 %102f",bonus);

}

59 输入四个整数,按大小顺序输出

main()

{int t,a,b,c,d;

printf("请输入四个数:");

scanf("%d,%d,%d,%d",&a,&b,&c,&d);

printf("\n\n a=%d,b=%d,c=%d,d=%d \n",a,b,c,d);

if(a>b)

{t=a;a=b;b=t;}

if(a>c)

{t=a;a=c;c=t;}

if(a>d)

{t=a;a=d;d=t;}

if(b>c)

{t=b;b=c;c=t;}

if(b>d)

{t=b;b=d;d=t;}

if(c>d)

{t=c;c=d;d=t;}

printf("\n 排序结果如下: \n");

printf(" %d %d %d %d \n",a,b,c,d);

}

510塔

main()

{

int h=10;

float x,y,x0=2,y0=2,d1,d2,d3,d4;

printf("请输入一个点(x,y):");

scanf("%f,%f",&x,&y);

d1=(x-x0)(x-x0)+(y-y0)(y-y0);

d2=(x-x0)(x-x0)+(y+y0)(y+y0);

d3=(x+x0)(x+x0)+(y-y0)(y-y0);

d4=(x+x0)(x+x0)+(y+y0)(y+y0);

if(d1>1 && d2>1 && d3>1 && d4>1)

h=0;

printf("该点高度为%d",h);

}

第六章 循环语句

61输入两个正数,求最大公约数最小公倍数

main()

{

int a,b,num1,num2,temp;

printf("请输入两个正整数:\n");

scanf("%d,%d",&num1,&num2);

if(num1<num2)

{

temp=num1;

num1=num2;

num2=temp;

}

a=num1,b=num2;

while(b!=0)

{

temp=a%b;

a=b;

b=temp;

}

printf("它们的最大公约数为:%d\n",a);

printf("它们的最小公倍数为:%d\n",num1num2/2);

}

62输入一行字符,分别统计出其中英文字母,空格,数字和其它字符的个数

解:

#include <stdioh>

main()

{

char c;

int letters=0,space=0,degit=0,other=0;

printf("请输入一行字符:\n");

while((c=getchar())!='\n')

{

if(c>='a'&&c<='z'||c>'A'&&c<='Z')

letters++;

else if(c==' ')

space++;

else if(c>='0'&&c<='9')

digit++;

else

other++;

}

printf("其中:字母数=%d 空格数=%d 数字数=%d 其它字符数=%d\n",letters,space,

digit,other);

}

63求s(n)=a+aa+aaa+…+aa…a之值,其中工是一个数字

解:

main()

{

int a,n,count=1,sn=0,tn=0;

printf("请输入a和n的值:\n");

scanf("%d,%d",&a,&n);

printf("a=%d n=%d \n",a,n);

while(count<=n)

{

tn=tn+a;

sn=sn+tn;

a=a10;

++count;

}

printf("a+aa+aaa+…=%d\n",sn);

}

64 求1+2!+3!+4!+…+20!

main()

{

float n,s=0,t=1;

for(n=1;n<=20;n++)

{

t=tn;

s=s+t;

}

printf("1!+2!+…+20!=%e\n",s);

}

65 main()

{

int N1=100,N2=50,N3=10;

float k;

float s1=0,s2=0,s3=0;

for(k=1;k<=N1;k++)/计算1到100的和/

{

s1=s1+k;

}

for(k=1;k<=N2;k++)/计算1到50各数平方和/

{

s2=s2+kk;

}

for(k=1;k<=N3;k++)

{

s3=s3+1/k;

}

printf("总和=%82f\n",s1+s2+s3);

}

66水仙开花

main()

{

int i,j,k,n;

printf(" '水仙花'数是:");

for(n=100;n<1000;n++)

{

i=n/100;

j=n/10-i10;

k=n%10;

if(i100+j10+k==iii+jjj+kkk)

{

printf("%d",n);

}

}

printf("\n");

}

67完数

main()

#include M 1000/定义寻找范围/

main()

{

int k0,k1,k2,k3,k4,k5,k6,k7,k8,k9;

int i,j,n,s;

for(j=2;j<=M;j++)

{

n=0;

s=j;

for(i=1;i<j;i++)

{

if((j%i)==0)

{

if((j%i)==0)

{

n++;

s=s-i;

switch(n)/将每个因子赋给k0,k1…k9/

{

case 1:

k0=i;

break;

case 2:

k1=i;

break;

case 3:

k2=i;

break;

case 4:

k3=i;

break;

case 5:

k4=i;

break;

case 6:

k5=i;

break;

case 7:

k6=i;

break;

case 8:

k7=i;

break;

case 9:

k8=i;

break;

case 10:

k9=i;

break;

}

}

}

if(s==0)

{

printf("%d是一个‘完数’,它的因子是",j);

if(n>1)

printf("%d,%d",k0,k1);

if(n>2)

printf(",%d",k2);

if(n>3)

printf(",%d",k3);

if(n>4)

printf(",%d",k4);

if(n>5)

printf(",%d",k5);

if(n>6)

printf(",%d",k6);

if(n>7)

printf(",%d",k7);

if(n>8)

printf(",%d",k8);

if(n>9)

printf(",%d",k9);

printf("\n");

}

}

方法二:此题用数组方法更为简单

main()

{

static int k[10];

int i,j,n,s;

for(j=2;j<=1000;j++)

{

n=-1;

s=j;

for(i=1;i<j;i++)

{

if((j%i)==0)

{

n++;

s=s-i;

k[n]=i;/将每个因子赋给k0,k1k9/

}

}

if(s==0)

{

printf("%d是一个完数,它的因子是:",j);

for(i=0;i<n;i++)

printf("%d,",k[i]);

printf("%d\n",k[n]);

}

}

58 有一个分数序列:2/1,3/2,5/3,8/5……求出这个数列的前20项之和

解: main()

{

int n,t,number=20;

float a=2,b=1,s=0;

for(n=1;n<=number;n++)

{

s=s+a/b;

t=a,a=a+b,b=t;

}

printf("总和=%96f\n",s);

}

69球反d问题

main()

{

float sn=1000,hn=sn/2;

int n;

for(n=2;n<=10;n++)

{

sn=sn+2hn;/第n次落地时共经过的米数/

hn=hn/2;/第n次反跳高度/

}

printf("第10次落地时共经过%f米 \n",sn);

printf("第10次反d%f米\n",hn);

}

610猴子吃桃

main()

{

int day,x1,x2;

day=9;

x2=1;

while(day>0)

{

x1=(x2+1)2;

x2=x1;

day--;

}

printf("桃子总数=%d\n",x1);

}

614打印图案

main()

{

int i,j,k;

for(i=0;i<=3;i++)

{

for(j=0;j<=2-1;j++)

printf(" ");

for(k=0;k<=2i;k++)

printf("");

printf("\n");

}

for(i=0;i<=2;i++)

{

for(j=0;j<=i;j++)

printf(" ");

for(k=0;k<=4-2i;k++)

printf("");

printf("\n");

}

615乒乓比赛

main()

{

char i,j,k;/i是a是对手;j是b是对手;k是c的对手/

for(i='x';i<='z';i++)

for(j='x';j<='z';j++)

{

if(i!=j)

for(k='x';k<='z';k++)

{

if(i!=k&&j!=k)

{if(i!='x' && k!='x' && k! ='z')

printf("顺序为:\na-%c\tb--%c\tc--%c\n",i,j,k);

}

}

}

}

71用筛选法求100之内的素数

/用筛选法求100之内的素数/

#include<mathh>

#define N 101

main()

{int i,j,line,a[N];

for(i=2;i<N;i++) a[i]=i;

for(i=2;i<sqrl(N);i++)

for(j=i+1;j<N;j++)

{if(a[i]!=0 && a[j]!=0)

if(a[j]%a[i]==0)

a[j]=0;

printf("\n");

for(i=2,line=0;i<N;i++)

{ if(a[i]!=0)

{printf("%5d",a[i]);

line++;

if(line==10)

{printf("\n");

line=0;}

}

}

72用选择法对10个数排序

/选择法排序/

#define N 10

main()

{ int i,j,min,temp,a[N];

/输入数据/

printf("请输入十个数:\n");

for (i=0;i<N;i++)

{ printf("a[%d]=",i);

scanf("%d",&a[i]);

}

printf("\n");

for(i=0;i<N;i++)

printf("%5d",a[i]);

printf("\n");

/排序/

for (i=0;i<N-1;i++)

{ min=i;

for(j=i+1;j<N;j++)

if(a[min]>a[j]) min=j;

temp=a[i];

a[i]=a[min];

a[min]=temp;

}

/输出/

printf("\n排序结果如下:\n");

for(i=0;i<N;i++)

printf("%5d",a[i]);

}

73对角线和:

/计算矩阵对角线元素之和/

main()

{

float a[3][3],sum=0;

int i,j;

printf("请输入矩阵元素:\n");

for(i=0;i<3;i++)

for(j=0;j<3;j++)

scanf("%f",&a[i][j]);

for(i=0;i<3;i++)

sum=sum+a[i][i];

printf("对角元素之和=62f",sum);

}

74插入数据到数组

/插入数据到数组/

main()

{int a[11]={1,4,6,9,13,16,19,28,40,100};

int temp1,temp2,number,end,i,j;

printf("初始数组如下:");

for (i=0;i<10;i++)

printf("%5d",a[i]);

printf("\n");

printf("输入插入数据:");

scanf("%d",&number);

end=a[9];

if(number>end)

a[10]=number;

else

{for(i=0;i<10;i++)

{ if(a[i]>number)

{temp1=a[i];

a[i]=number;

for(j=i+1;j<11;j++)

{temp2=a[j];

a[j]=temp1;

temp1=temp2;

}

break;

}

}

}

for(i=0;j<11;i++)

printf("a%6d",a[i]);

}

75将一个数组逆序存放。

/数组逆序存放/

#define N 5

main()

{ int a[N]={8,6,5,4,1},i,temp;

printf("\n 初始数组:\n");

for(i=0;i<N;i++)

printf("%4d",a[i]);

for(i=0;i<N/2;i++)

{ temp=a[i];

a[i]=a[N-i-1];

a[N-i-1]=temp;

}

printf("\n 交换后的数组:\n");

for(i=0;i<N;i++)

printf("%4d",a[i]);

}

76杨辉三角

/打印杨辉三角形/

#define N 11

main()

{ int i,j,a[N][N];

for(i=1;i<N;i++)

{a[i][i]=1;

a[i][1]=1;

}

for(i=3;i<N;i++)

for(j=2;j<=i-1;j++)

a[i][j]=a[i01][j-1]+a[i-1][j];

for(i=1;i<N;i++)

{ for(j=1;j<=i;j++)

printf("%6d",a[i][j];

printf("\n");

}

printf("\n");

}

78鞍点

/查找鞍点/

#define N 10

#define M 10

main()

{ int i,j,k,m,n,flag1,flag2,a[N][M],max,maxi,maxj;

printf("\n输入行数n:");

scanf("%d",&n);

printf("\n输入列数m:");

scanf("%d",&m);

for(i=0;i<n;i++)

{ printf("第%d行\n",i);

for(j=0;j<m,j++);

scanf("%d",&a[i][j];

}

for(i=0;i<n;i++)

{ for(j=0;j<m;j++)

printf("%5d",a[i][j]);

pritf("\n");

}

flag2=0;

for(i=0;i<n;i++)

{ max=a[i][0];

for(j=0;j<m;j++)

if(a[i][j]>max)

{ max=a[i][j];

maxj=j;

}

for (k=0,flag1=1;k<n && flag1;k++)

if(max>a[k][max])

flag1=0;

if(flag1)

{ printf("\n第%d行,第%d列的%d是鞍点\n",i,maxj,max);

flag2=1;

}

}

if(!flag2)

printf("\n 矩阵中无鞍点! \n");

}

79变量说明:top,bott:查找区间两端点的下标;loca:查找成功与否的开关变量

/折半查找/

#include<stdioh>

#define N 15

main()

{ int i,j,number,top,bott,min,loca,a[N],flag;

char c;

printf("输入15个数(a[i]>[i-1])\n);

scanf("%d",&a[0]);

i=1;

while(i<N)

{ scanf("%d",&a[i]);

if(a[i]>=a[i-1])

i++;

esle

{printf("请重输入a[i]");

printf("必须大于%d\n",a[i-1]);

}

}

printf("\n");

for(i=0;i<N;i++)

printf("%4d",a[i]);

printf("\n");

flag=1;

while(flag)

{

printf("请输入查找数据:");

scanf("%d",&number);

loca=0;

top=0;

bott=N-1;

if((number<a[0])||(number>a[N-1]))

loca=-1;

while((loca==0)&&(top<=bott))

{ min=(bott+top)/2;

if(number==a[min])

{ loca=min;

printf("%d位于表中第%d个数\n",number,loca+1);

}

else if(number<a[min])

bott=min-1;

else

top=min+1;

}

if(loca==0||loca==-1)

printf("%d不在表中\n",number);

printf("是否继续查找Y/N!\n");

c=getchar();

if(c=='N'||c=='n')

flag=0;

}

}

710/统计字符数/

main()

{ int i,j,uppn,lown,dign,span,othn;

char text[3][80];

uppn=lown=dign=span=othn=0;

for(i=0;i<3;i++)

{ printf("\n请输入第%d行:\n",i);

gets(text[i]);

for(j=0;j<80 && text[i][j]!='\0';j++)

{if(text[i][j]>='A' && text[i][j]<='Z')

uppn+=1;

else if(text[i][j]>='a' && text[i][j]<='z')

lown+=1;

else if(text[i][j]>='1' && text[i][j]<='9')

dign+=1;

else if(text[i][j]=' ')

span+=1;

else

othn+=1;

}

}

for(i=0;i<3;i++)

printf("%s=n",text[i]);

printf("大写字母数:%d\n",uppn);

printf("小写字母数:%d\n",lown);

printf("数字个数:%d\n",dign);

printf("空格个数:%d\n",span);

printf("其它字符:%d\n",othn);

}

711/打印图案/

main()

{static char a[5]={'','','','',''};

int i,j,k;

char space=' ';

for(i=0;i<=5;i++)

{printf("\n");

for(j=1;j<=3i;j++)

printf("%lc",space);

for(k=0;k<=5;k++)

printf("%3c",a[k];

}

}

712/译电文/

#include<stdioh>

main()

{int i,n;

char ch[80],tran[80];

printf("请输入字符:");

gets(ch);

printf("\n密码是%c",ch);

i=0;

while(ch[i]!='\0')

{if((ch[i]>='A')&&(ch[i]<='Z'))

tran[i]=26+64-ch[i]+1+64;

else if((ch[i]>='a')&&(ch[i]<='z'))

tran[i]=26+96-ch[i]+1+96;

else

tran[i]=ch[i];

i++;

}

n=i;

printf("\n原文是:");

for(i=0;i<n;i++)

putchar(tran[i]);

}

713/连接两个字符串(不用'stract')/

main()

{

char s1[80],s2[40];

int i=0,j=0;

printf("\n请输入字符串1:");

scanf("%s",s1);

printf("\n请输入字符串2:");

scanf("%s",s2);

while(s1[i]!='\0')

i++;

while(s2[j]!='\0')

s1[i++]=s2[j++];

s1[i]='\0';

printf("\n连接后字符串为:%s",s1);

}

714/字符串比较/

#include<stdioh>

main()

{int i,resu;

char s1[100],s2[100];

printf("请输入字符串1:\n");

gets(s1);

printf("\n 请输入字符串2:\n");

gets(s2);

i=0;

while((s1[i]==s2[i]) && (s1[i]!='\0'))i++;

if(s1[i]=='\0' && s2[i]=='\0')resu=0;

else

resu=s1[i]-s2[i];

printf(" %s与%s比较结果是%d",s1,s2,resu);

}

715/字符串复制/

#include<stdioh>

main()

{

char from[80],to[80];

int i;

printf("请输入字符串");

scanf("%s",from);

for(i=0;i<=strlen(from);i++)

to[i]=from[i];

printf("复制字符串为:%s\n",to);

}

第八章 函数

81(最小公倍数=uv/最大公约数)

hcf(u,v)

int u,v;

(int a,b,t,r;

if(u>v)

{t=u;u=v;v=t;}

a=u;b=v;

while((r=b%a)!=0)

{b=a;a=r;}

return(a);

}

lcd(u,v,h)

int u,v,h;

{int u,v,h,l;

scanf("%d,%d",&u,&v);

h=hcf(u,v);

printf("HCF=%d\n",h);

l=lcd(u,v,h);

printf("LCd=%d\n",l);

}

{return(uv/h);}

main()

{int u,v,h,l;

scanf("%d,%d",&u,&v);

h=hcf(u,v);

printf("HCF=%d\n",h);

l=lcd(u,v,h);

printf("LCD=%d\n",l);

}

82求方程根

#include<mathh>

float x1,x2,disc,p,q;

greater_than_zero(a,b)

float a,b;

{

x1=(-b+sqrt(disc))/(2a);

x2=(-b-sqrt(disc))/(2a);

}

equal_to_zero(a,b)

float a,b;

{x1=x2=(-b)/(2a);}

smaller_than_zero(a,b)

float a,b;

{p=-b/(2a);

1/(1+1/(1+1/(x+y)));

x(x(x(ax+b)+c)+d)+e;

log(1+pow(fabs((a+b)/(a-b)),10));

sqrt(1+pi/2cos(48));

1/tan((1-xx)/(1+xx));

//由于c语言中没提供cot函数,所以就用tan的倒数表示了。

log10(aa+ab+bb);

Ardian Bujupi---Rise to the Top

I got infinite energy,

and I'm going to the top,

no one stopping me

And if you wanna come with me,

you better rise to the occasion,

prepare for the invasion

Aim for the stars,

there's no turning back,

we gonna lay it on the line,

got it, roger that

And if they put up a fight,

oh, we can dance all night,

I will never back down,

you can count on that

People across the world,

they'll be ready for you,

so many beautiful girls,

doing what you want to

Can you handle the pressure,

being on that level,

paparazzi taking shots,

like Bacardi on the rocks,

Rise to the top,

rise, rise to the top,

ain't nobody gonna stop,

our shine at the top

Turn up the levels,

fire blazing, be incredible,

rise, rise to the top,

rise, rise to the top

Ready for mission impossible,

tune in the satellite briefing,

turn on the radio

Unstrap your seat belts,

just lose control,

and go bananas if you feel it,

don't slip if you feel it

Aim for the stars,

there's no turning back,

we gonna lay it on the line,

got it, roger that

I'm gonna head to a place where great,

just doesn't cut it,

and the limit is just the beginning

People across the world,

they'll be ready for you,

so many beautiful girls,

doing what you want to

Can you handle the pressure,

being on that level,

paparazzi taking shots,

like Bacardi on the rocks

Rise to the top,

rise, rise to the top,

ain't nobody gonna stop,

our shine at the top

Turn up the levels,

fire blazing, be incredible,

rise, rise to the top,

rise, rise to the top蛮好听的哈!祝好!

1、首先在电脑中打开matlab软件,输入figure(111);也就是创建一个图形窗口,窗口的名称是111。

2、创建后图形后,图形的系统是axes。此时创建第一个axes,句柄为ax2。

3、此时可以通过plot画图,其中自定义部分是显得属性。

4、接着对ax2进行句柄set。其中最重要的set内容是Y轴的位置。“YAxisLocation” ‘Life’或者“Right”,另外需要将box off。

5、既然是双Y轴,通过前面已经创建了一个Y轴。只需要灵活使用上面的代码就可以创建另一个Y轴。然后运行程序,就完成了。

6、此时,生成的figure(111)就是一个双Y轴的图形。

以上就是关于matlab绘图如何添加图例/坐标轴刻度全部的内容,包括:matlab绘图如何添加图例/坐标轴刻度、有答案的请进……、C++:算术表达式求值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10067401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存