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,'