77范文网 - 专业文章范例文档资料分享平台

经典C语言程序设计100例(11)

来源:网络收集 时间:2021-09-24 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

1. 程序分析:
2.程序源代码:
#define nmax 50
#include<stdio.h>
viod main()
{
int i,k,m,n,num[nmax],*p;
printf("please input the total of numbers:");
scanf("%d",&n);
p=num;
for(i=0;i<n;i++)
  *(p+i)=i+1;
  i=0;
  k=0;
  m=0;
  while(m<n-1)
  {
  if(*(p+i)!=0) k++;
  if(k==3)
  { *(p+i)=0;
  k=0;
  m++;
  }
i++;
if(i==n) i=0;
}
while(*p==0) p++;
printf("%d is left\n",*p);
}
-----------------------------------------------------------------------------
【程序70】:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。   
1.程序分析:
2.程序源代码:
#include<stdio.h>
viod main()
{
int len;
char *str[20];
printf("please input a string:\n");
scanf("%s",str);
len=length(str);
printf("the string has %d characters.",len);
}
length(p)
char *p;
{
int n;
n=0;
while(*p!='\0')
{
  n++;
  p++;
}
return n;
}
-----------------------------------------------------
------------------------
【程序71】:编写input()和output()函数输入,输出5个学生的数据记录。
1.程序分析:
2.程序源代码:
#include<stdio.h>
#define N 5
struct student
{

char num[6];
  char name[8];
  int score[4];
} stu[N];
input(stu)
struct student stu[];
{ int i,j;
  for(i=0;i<N;i++)
  { printf("\n please input %d of %d\n",i+1,N);
   printf("num: ");
   scanf("%s",stu[i].num);
   printf("name: ");
   scanf("%s",stu[i].name);
    for(j=0;j<3;j++)
    { printf("score %d.",j+1);
     scanf("%d",&stu[i].score[j]);
    }
   printf("\n");
  }
}
print(stu)
struct student stu[];
{ int i,j;
printf("\nNo. Name Sco1 Sco2 Sco3\n");
for(i=0;i<N;i++)
{ printf("%-6s%-10s",stu[i].num,stu[i].name);
  for(j=0;j<3;j++)
   printf("%-8d",stu[i].score[j]);
  printf("\n");
}
}
viod main()
{
  input();
  print();
}
-----------------------------------------------------------------------------
【程序72】:创建一个链表。
1.程序分析:           
2.程序源代码:
/*creat a list*/
#include "stdlib.h"
#include <stdio.h>
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
viod main()
{ link ptr,head;
int num,i;
ptr=(link)malloc(sizeof(node));
ptr=head;
printf("please input 5 numbers==>\n");
for(i=0;i<=4;i++)
{
  scanf("%d",&num);
  ptr->data=num;
  ptr->next=(link)malloc(sizeof(node));
  if(i==4) ptr->next=NULL;
  else ptr=ptr->next;
}
ptr=head;
while(ptr!=NULL)
{ printf("The value is ==>%d\n",ptr->data);
  ptr=ptr->next;
}
}
-----------------------------------------------------------------------------
【程序73】:反向输出一个链表。   
1.程序分析:
2.程序源代码:
/*reverse output a list*/
#include "stdlib.h"
#include <stdio.h>
struct list
{ int data;
  struct list *next;
};
typedef struct list node;
typedef node *link;
viod main()
{ link ptr,head,tail; 
  int num,i;
  tail=(link)malloc(sizeof(node));
  tail->next=NULL;
  ptr=tail;
  printf("\nplease input 5 data==>\n");
  for(i=0;i<=4;i++)
  {
   scanf("%d",&num);
   ptr->data=num;
   head=(link)malloc(sizeof(node));
   head->next=ptr;
   ptr=head;
  }
ptr=ptr->next;
while(ptr!=NULL)
{ printf("The value is ==>%d\n",ptr->data);
  ptr=ptr->next;
}}
-----------------------------------------------------------------------------
【程序74】:连接两个链表。
1.程序分析:
2.程序源代码:
#include "stdlib.h"
#include <stdio.h>
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
link delete_node(link pointer,link tmp)
{if (tmp==NULL) /*delete first node*/
  return pointer->next;
else
{ if(tmp->next->next==NULL)/*delete last node*/
   tmp->next=NULL;
  else /*delete the other node*/
   tmp->next=tmp->next->next;
  return pointer;
}

}
void selection_sort(link pointer,int num)
{ link tmp,btmp;
  int i,min;
  for(i=0;i<num;i++)

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说公务员考试经典C语言程序设计100例(11)在线全文阅读。

经典C语言程序设计100例(11).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/gongwuyuan/1248575.html(转载请注明文章来源)

相关推荐:

Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: