1、把整数分解成素数 如90=2*3*3*5 【见2015年】

方法一:

int main()
{
int n, i=2;
printf("\nInput:");
scanf("%d", &n);
printf("=");
i = 2;
while (n > 1)
{
if (n%i == 0)
{
printf("%d", i);
n = n / i;
if (n > 1) printf("*");
}
else i++; // 如果不能整除时,说明不是其素数
}
return 0;
}

方法二:

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h> //判读是否为质数,并带回它的最小因数(除1之外)。
int isprime(int value, int *submultiple)
{
int i;
for (i=2; i<(int)sqrt(value)+1; i++)
{
if ((value%i)==0)
{
*submultiple=i;
return 0;
}
}
return 1;
}
//递归调用,如果为质数则打印出来,否则将该数除以它的最小因数(除1之外)后递归调用
void prime_submultiple(int value)
{
int submultiple;
if (isprime(value,&submultiple))
{
printf("%d",value);
return;
}
else
{
printf("%d*",submultiple);
prime_submultiple(value/submultiple);
return;
}
}
int main()
{
int x;
printf("\nPlease input a integar:");
scanf("%d",&x);
printf("%d=",x);
prime_submultiple(x);
}

方法三:

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
//判断是否为质数,并带回他的最小因数(1除外),这个最小因数为素数
int IfPrime(int value,int *submultiple)
{
int i;
for(i=2; i <sqrt(value); i++)
{
if(0 == value%i)
{
*submultiple =i;
return 0;
}
}
return 1;
}
//递归调用,如果为质数则直接打印出来,否则为合数,将该合数除以它的最小因数(1除外)后递归调用
void primre_submultiple(int value)
{
int submultiple;
//value为质数(素数)
if(IfPrime(value,&submultiple))
{
printf("%d",value);
return;
}
else
{
printf("%d*",submultiple);
primre_submultiple(value/submultiple);
return;
}
}
void main()
{
int idata;
printf("please input a integar:");
scanf("%d",&idata);
printf("%d = ",idata);
primre_submultiple(idata);
printf("\n");
}

2、计算1-x+x^2/2!-x^3/3!+.....+x^n/n! 见【2015相似】

方法一:

#include<stdio.h>

int Calculate(int x,int n)
{
int total=0;
int itemp_a=x,itemp_b=1;
int i,j;
for(i=0; i <= n; i++)
{
if(0 == i)
{
total +=1;
printf("%d : total=%d\n",i,total);
}
else if(1 == i)
{
total = total-x;
printf("%d : total=%d\n",i,total);
}
else
//===oushu
{
if((0 == i%2))
{
itemp_a =1;
itemp_b =1;
for(j=i; j>= 1; j--)
{
itemp_a *=x;
itemp_b *=j;
printf("itemp_a=%d, itemp_b=%d\n",itemp_a,itemp_b);
}
printf("%d : total=%d\n",i,total);
total +=(itemp_a/itemp_b);
printf("%d,total:%d\n",i,total);
}
else
{
itemp_a =1;
itemp_b =1;
for(j=i; j>= 1; j--)
{
itemp_a *=x;
itemp_b *=j;
printf("itemp_a=%d, itemp_b=%d\n",itemp_a,itemp_b);
}
printf("%d : total=%d\n",i,total);
total = total-(itemp_a/itemp_b);
printf("%d,total:%d\n",i,total);
}
}
}
printf("%d,total:%d\n",i,total);
return total;
}
void main()
{
int x;
int n;
int total;
printf("please input the data of x,n!\n");
scanf("%d %d",&x,&n);
total = Calculate(x,n);
printf("OK,the result is: %d\n",total);
}

方法二:

#include <stdio.h>
#include <stdlib.h> void main()
{
int n, x, j, i = 1;
float sum = 1, k = 1;
printf("Input n and x:\n");
scanf("%d %d", &n, &x);
while (i <= n)
{
k = 1;
for (j = 1; j <= i; j++)
{
k = -1*k*x;
}
for (j = 1; j <= i; j++)
{
k = k/ j;
}
sum += k;
i++;
}
printf("%f\n", sum);
}

方法三:动态规划

#include <stdio.h>
#include <stdlib.h> void main()
{
int n,x,i=1;
float sum = 1,k = 1;
printf("Input n and x:\n");
scanf("%d %d", &n, &x);
while (i <= n)
{
k = -1 * k*x / i;
sum += k;
i++;
}
printf("%f", sum);
}

3、删除输入的字符串中的大小写字母和数字 并统计有重复的字符及其重复次数

 


4、输入整形数据,按输入的逆序建立单链表 【见2016年19题】

代码:

#include <stdio.h>
#include <stdlib.h> typedef struct slist{
int data;
struct slist *next;
}; int main()
{
//逆序建立单链表,头插法
int x;
struct slist *p,*head = (struct slist *)malloc(sizeof(struct slist));
head ->next = NULL;
printf("请输入元素:\n");
scanf("%d",&x);
while(x != 9999)
{
struct slist *node = (struct slist *)malloc(sizeof(struct slist));
node ->data = x;
node ->next = head ->next;
head ->next = node;
scanf("%d",&x);
}
//输出
printf("单链表为:");
p = head ->next;
while(p != NULL)
{
printf("%d\t",p ->data);
p = p->next;
}
return 0;
}


5、单链表逆序 【见2017.24】

方法一:头插法

代码:

#include <stdio.h>
#include <stdlib.h> typedef struct slist
{
int data;
struct slist *next;
};
struct slist *head; // 尾插法建立链表
void creatslist()
{
int x;
head = (struct slist *)malloc(sizeof(struct slist)); //头结点
struct slist *p,*node; // q为尾指针
p = head; printf("请输入元素:");
scanf("%d",&x);
while(x != 9999)
{
node = (struct slist *)malloc(sizeof(struct slist));
node ->data = x;
p ->next = node;
p = node;
printf("请输入元素:");
scanf("%d",&x);
}
p ->next = NULL;
}
//链表输出打印
void inputslist()
{
struct slist *q;//q是工作指针
q = head ->next; //头结点无元素
while(q != NULL)
{
printf("%d\t",q ->data);
q = q ->next;
}
}
// 方法一:头插法 逆序链表
void reverseslist1()
{
struct slist *p,*r; // p是工作指针,r是p的后继,以防断链
p = head ->next; //从第一个元素开始
head ->next = NULL; //将头节点后置null,断开
while(p != NULL)
{
r = p ->next; // r暂存s后继
p ->next = head ->next; // 依次将元素结点摘下
head ->next = p;
p = r;
}
}
void main()
{
creatslist();
inputslist();
printf("\n逆序后:\n");
reverseslist1();
inputslist();
}

方法二: 后继指针指向前驱结点

代码:

#include <stdio.h>
#include <stdlib.h> typedef struct slist
{
int data;
struct slist *next;
};
struct slist *head; // 尾插法建立链表
void creatslist()
{
int x;
head = (struct slist *)malloc(sizeof(struct slist)); //头结点
struct slist *p,*node; // q为尾指针
p = head; printf("请输入元素:");
scanf("%d",&x);
while(x != 9999)
{
node = (struct slist *)malloc(sizeof(struct slist));
node ->data = x;
p ->next = node;
p = node;
printf("请输入元素:");
scanf("%d",&x);
}
p ->next = NULL;
}
//链表输出打印
void inputslist()
{
struct slist *q;//q是工作指针
q = head ->next; //头结点无元素
while(q != NULL)
{
printf("%d\t",q ->data);
q = q ->next;
}
}
// 方法二:后继指针指向前驱结点
void reverseslist2()
{
struct slist *pre,*p = head ->next,*r =p ->next;
p ->next = NULL; //处理第一个结点
while(r != NULL) // r若为空,则p为最后一个节点
{
pre = p;
p = r;
r = r ->next;
p ->next = pre;
}
head ->next = p; //处理最后一个结点
} void main()
{
creatslist();
inputslist();
printf("\n逆序后:\n");
reverseslist2();
inputslist();
}

C 2013笔试题的更多相关文章

  1. 腾讯2013笔试题—web前端笔试题 (老题练手)

    问题描述(web前端开发附加题1): 编写一个javascript的函数把url解析为与页面的javascript.location对象相似的实体对象,如:url :'http://www.qq.co ...

  2. Google 2013笔试题一

    2.1 给定三个整数a,b,c,实现 int median(int a, int b, int c),返回三个数的中位数,不可使用sort,要求整数操作(比较,位运算,加减乘除等)次数尽量少,并分析说 ...

  3. 阿里巴巴2013年实习生笔试题B

    阿里巴巴集团2013实习生招聘技术类笔试题(B) 一.单向选择题 1.在常用的网络协议中,___B__是面向连接的.有重传功能的协议. A. IP B. TCP C. UDP D. DXP 2.500 ...

  4. Microsoft 2013校园招聘笔试题及解答

    Microsoft 2013校园招聘笔试题及解答 题目是自己做的,求讨论.吐槽.拍砖 1.      Which of the following callingconvension(s) suppo ...

  5. Java中有关构造函数的一道笔试题解析

    Java中有关构造函数的一道笔试题解析 1.详细题目例如以下 下列说法正确的有() A. class中的constructor不可省略 B. constructor必须与class同名,但方法不能与c ...

  6. 剑指Offer——笔试题+知识点总结

    剑指Offer--笔试题+知识点总结 情景回顾 时间:2016.9.23 12:00-14:00 19:00-21:00 地点:山东省网络环境智能计算技术重点实验室 事件:笔试 注意事项:要有大局观, ...

  7. 某公司的U3D笔试题

    某公司的U3D笔试题   今天这套笔试题感觉做得一般. 随后是二对一的技术面试,但涉及的技术细节相对较少,更多的是对以前工作.项目经历的询问. 然后说今天先到这里,让我等通知. 我还特意问了一下,通知 ...

  8. 对Thoughtworks的有趣笔试题实践

    记得2014年在网上看到Thoughtworks的一道笔试题,当时觉得挺有意思,但是没动手去写.这几天又在网上看到了,于是我抽了一点时间写了下,我把程序运行的结果跟网上的答案对了一下,应该是对的,但是 ...

  9. 从阿里巴巴笔试题看Java加载顺序

    一.阿里巴巴笔试题: public class T implements Cloneable { public static int k = 0; public static T t1 = new T ...

随机推荐

  1. curl_getinfo的巧用

    最近使用curl的时候,发现了一个比较好用的函数,当然是初级者适用的一个函数,就是curl_getinfo(), 在抓取一个页面的时候,会遇到302页面跳转的情况,刚开始处理的时候,是用curl抓取一 ...

  2. Ubuntu日常使用总结

    Contents 使用了将近一年的Ubuntu,感觉不用windows也可以处理日常的事务.并且我相信只要合理利用Ubuntu,一定可以取代你手中的Windows.我不是说Ubuntu有多么好,只是从 ...

  3. Android开发常见错误

    1.出现 “Unable to resolve target 'android-9'”,解决办法: 一般移植别人工程会出现此错误. 右键项目文件--->properties--->andr ...

  4. IO和流

    I/O和流 I/O是Input和Output的缩写 从读写设备,包括硬盘文件,内存,键盘输入,屏幕输出,网路 输入输出"内容"(字节或文本) 流是对输入输出设备的一种抽象 从流中读 ...

  5. FPGA小白学习之路(4)PLL中的locked信号解析(转)

    ALTPLL中的areset,locked的使用 转自:http://www.360doc.com/content/13/0509/20/9072830_284220258.shtml 今天对PLL中 ...

  6. 从0开发3D引擎(补充):介绍领域驱动设计

    我们使用领域驱动设计(英文缩写为DDD)的方法来设计引擎,在引擎开发的过程中,领域模型会不断地演化. 本文介绍本系列使用的领域驱动设计思想的相关概念和知识点,给出了相关的资料. 上一篇博文 从0开发3 ...

  7. appium+python自动化实践之查找元素的等待方式笔记

    元素等待作用 设置元素等待,可以更加灵活的制定等待定位元素的时间,从而增强脚本的健壮性,提高执行效率. 元素等待类型 强制等待:设置固定等待时间,使用sleep()方法即可实现 from time i ...

  8. 使用 EOLINKER 进行接口测试的最佳路径 (上)

    本文内容: 测试脚本管理:讲述如何在 EOLINKER 上设计测试项目目录结构. 编写测试脚本:讲述如何在 EOLINKER 上编写接口测试脚本. 测试脚本执行及报告:讲述如何在 EOLINKER 上 ...

  9. 使用CSS实现折叠面板总结

    任务目的 深入理解html中radio的特性 深入理解CSS选择器以及伪元素的使用 任务描述 使用input的radio单选框特性结合CSS中的伪元素实现bootstrap中折叠面板(点击查看样例), ...

  10. 在服务器上保存图片没有权限该怎么办?Permission denied:xxxxxx

    用Flask框架,写了一个上传图片的接口,把这个Flask服务用nginx+uwsgi部署在了服务器上,保存图片至服务器指定目录,显示没有权限?? 一开始我以为是nginx或者uwsgi影响的(可能很 ...