c语言指针程序设计
❶ c语言用指针来完成的程序设计
#include<stdio.h>
struct student
{
char name[10];
float math;
float english;
float c;
};
void main(int arbc, char *argv[])
{
struct student stu[10], *ss = stu;
int i;
float sum[10] = {0}, aver[10] = {0};
for(i = 0; i < 10; i++)
{
printf("please input student name: \n");
scanf("%s", ss->name);
printf("please input student score of math: \n");
scanf("%f", &(ss->math));
printf("please input student score of english \n");
scanf("%f", &(ss->english));
printf("please input student score of c: \n");
scanf("%f", &(ss->c));
sum[i] += ss->math + ss->english + ss->c;
aver[i] = sum[i] / 3;
ss++;
}
for(i=0; i < 10; i++)
{
printf("student[%d]: %s\tsum of score: %f, average: %f\n", i, stu[i].name, sum[i], aver[i]);
}
}
❷ C语言指针编程
代码文本:
#include "stdio.h"
#define N 10
#define F(x) ((x)>0 ? (x) : -(x))
int f(int *p){
int i,mini;
for(mini=0,i=1;i<N;i++)
if(F(p[mini]) > F(p[i]))
mini=i;
printf("%d ",p[mini]);
return mini;
}
int main(int argc,char *argv[]){
int a[N],i;
printf("Enter the %d integers... ",N);
for(i=0;i<N;scanf("%d",a+i++));
printf("The subscript is %d ",f(a));
return 0;
}
❸ 设计一个程序(C语言 指针)
//DEVC
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#defineN20
typedefstruct
{
charname[10];
intage;
intsex;
intgrade;
intnclass;
introom;
}INFO;
intmain()
{
char*name1[20]={"张","王","李","赵","钱","孙","蒋","秦","任","刘","周","郑","吴","朱","许","何","吕","谢","方","叶"};
char*name2[20]={"子","欣","晨","紫","诗","梦","嘉","一","思","静","可","佳","心","梓","俊","明","浩","博","文","天"};
char*name3[20]={"轩","勇","涛","军","浩","豪","宇","俊","鸣","熙","文","国","佑","泽","然","杰","远","平","秋","飞"};
srand((unsigned)time(0));
INFO*s;
s=(INFO*)malloc(sizeof(INFO)*N);
intn,i;
for(i=0;i<N;i++)//随机初始N个同学姓名年龄,性别,班级等数据
{
n=rand()%20;
strcpy(s[i].name,name1[n]);
n=rand()%20;
strcat(s[i].name,name2[n]);
n=rand()%20;
strcat(s[i].name,name3[n]);
//以上为随机生成姓名
s[i].age=rand()%3+16;
s[i].sex=rand()%2;
s[i].grade=rand()%3+1;
s[i].nclass=rand()%6+1;
s[i].room=100*(rand()%5+1)+rand()%20+1;
}
for(i=0;i<N;i++)
{
printf("%s%d岁",s[i].name,s[i].age);
if(s[i].sex==1)
{
printf("男");
}
else
{
printf("女");
}
printf("%d年级%d班%d室 ",s[i].grade,s[i].nclass,s[i].room);
}
charch[50];
intfind;
while(1)
{
find=0;
memset(ch,'