落第骑士英雄谭bd:求:指针编程3题(快啊)谢谢

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 17:22:06
1)假设有int型变量x、bool型变量y和double型数组a[5]。
按以下要求编写程序:
(a)为x和y随便设置一个值,输出其值和地址。
(b)利用随机数产生数组a的5个元素,要求其整数和小数部分都是2位。
利用指针输出数组a的各个元素及数组的首地址。
(c)输出字符串常量"pointer"的首地址,并输出该字符串,要求每个字符之间空一个格。

2)输入一个字符串,内中有数字字符和非数字字符,将其中的连续数字作为一个整数,
编写程序计算其中有多少个整数,并输出所有整数。
例如:若输入的字符串为:a123x456Ub17960?302tab0586ee,
则应输出:共5个整数 123 456 17960 302 586。

3)编写程序,输入月份号,输出该月的英文名称。
例如,若输入3,则输出March,要求用指针数组处理。

1)
#include <stdio.h>
#include <conio.h>
static unsigned long int next=1;
int rand0(void)
{
next=next*89975414201+18757;
return (unsigned int)(next/65536)%32768+65;
}

int main(void)
{
int count;
int x=2;
double y=3.5;
char *chp="HelloWorld";
printf("value: %d address: %xd\n",x,&x);
printf("value: %f address: %xd\n",y,&y);
for(count=0;count<5;count++)
printf("random number %d: %2.2f\n",count+1,rand0()/655.+rand0()/655.);
printf("The head address of the string is:%xd\n",&chp);
printf("The string is: ");
for(count=0;count<strlen(chp);count++)
printf("%c ",chp[count]);
printf("\n");
getch();
return 0;
}

2)
#include "stdio.h"
#include "conio.h"
#include "string.h"

main()
{
char str[100];
char temp[100]={0};
int i=0,j=0;
gets(str);
for(i=0;i<strlen(str);i++)
{
if(i==strlen(str)-1)
{
temp[j++]=str[i];
goto Mk;}
if(str[i]<='9'&&str[i]>='0')
temp[j++]=str[i];
else
{
Mk:if(temp[0]!='\0')
{
temp[j]='\0';
j=0;
printf("%s ",temp);
temp[0]='\0';
}
}
}
getch();
}

3)
#include "stdio.h"
#include "conio.h"
#include "string.h"

main()
{
int i;
char *ch[12]={"Janunary","February","March","April",
"May","June","July","August","September","October","December","November"};
scanf("%d",&i);
printf("%s\n",ch[i-1]);

getch();
}

1)
#include <stdio.h>
#include <stdlib.h>
#icnlude <time.h>
int main()
{
//part a
int x=4;
bool y=true;
printf("x=%d,addrX=%d\n",x,&x);
printf("y=%d,addrY=%d\n",y,&y);

//part b
srand(time(null));
int i;
double a[5];
for(i=0;i<5;i++)
{
int ta=rand()%100;
int tb=rand()%100;
a[i]=ta+tb/100.0;
printf("%d ",a+i);

}
printf("首地址:%d",&a);

//part c
char *str="point";
printf("首地址:%d",&str);
char *p=str;
while(*p!='\0')
{
printf("%c ",*p);
p++;
}
}

2)
#include <stdio.h>
int main()
{
char str[100];
scanf("%s\n",&str);
int count=0;
char *p=str;
while(*p!='\0')
{
int sig=0;
while(*p>='0' && *p<='9')
{
printf("%c",*p);
sig=1;
p++;
}
if(sig==1)
{
count++;
printf(" ");
}
}
printf("共有%d个整数:",count);
}
3)
#include <stdio.h>
int main()
{
char *month[12]={"Jan","Feb",,自己输入剩余的};
char ch;
scanf("%c",ch);
printf(month+i);
}