求:指针编程3题(快啊)谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/21 16:15:43
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"

mai