C 2013笔试题
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笔试题的更多相关文章
- 腾讯2013笔试题—web前端笔试题 (老题练手)
问题描述(web前端开发附加题1): 编写一个javascript的函数把url解析为与页面的javascript.location对象相似的实体对象,如:url :'http://www.qq.co ...
- Google 2013笔试题一
2.1 给定三个整数a,b,c,实现 int median(int a, int b, int c),返回三个数的中位数,不可使用sort,要求整数操作(比较,位运算,加减乘除等)次数尽量少,并分析说 ...
- 阿里巴巴2013年实习生笔试题B
阿里巴巴集团2013实习生招聘技术类笔试题(B) 一.单向选择题 1.在常用的网络协议中,___B__是面向连接的.有重传功能的协议. A. IP B. TCP C. UDP D. DXP 2.500 ...
- Microsoft 2013校园招聘笔试题及解答
Microsoft 2013校园招聘笔试题及解答 题目是自己做的,求讨论.吐槽.拍砖 1. Which of the following callingconvension(s) suppo ...
- Java中有关构造函数的一道笔试题解析
Java中有关构造函数的一道笔试题解析 1.详细题目例如以下 下列说法正确的有() A. class中的constructor不可省略 B. constructor必须与class同名,但方法不能与c ...
- 剑指Offer——笔试题+知识点总结
剑指Offer--笔试题+知识点总结 情景回顾 时间:2016.9.23 12:00-14:00 19:00-21:00 地点:山东省网络环境智能计算技术重点实验室 事件:笔试 注意事项:要有大局观, ...
- 某公司的U3D笔试题
某公司的U3D笔试题 今天这套笔试题感觉做得一般. 随后是二对一的技术面试,但涉及的技术细节相对较少,更多的是对以前工作.项目经历的询问. 然后说今天先到这里,让我等通知. 我还特意问了一下,通知 ...
- 对Thoughtworks的有趣笔试题实践
记得2014年在网上看到Thoughtworks的一道笔试题,当时觉得挺有意思,但是没动手去写.这几天又在网上看到了,于是我抽了一点时间写了下,我把程序运行的结果跟网上的答案对了一下,应该是对的,但是 ...
- 从阿里巴巴笔试题看Java加载顺序
一.阿里巴巴笔试题: public class T implements Cloneable { public static int k = 0; public static T t1 = new T ...
随机推荐
- 来自ebay内部的「软件测试」学习资料,覆盖GUI、API自动化、代码级测试及性能测试等,Python等,拿走不谢!...
在软件测试领域从业蛮久了,常有人会问我: 刚入测试一年,很迷茫,觉得没啥好做的-- 测试在公司真的不受重视,我是不是去转型做开发会更好? 资深的测试架构师的发展路径是怎么样的?我平时该怎么学习? 我 ...
- 会编程的 AI + 会修 Bug 的 AI,等于什么 ?
2017-02-25 Python开发者 (点击上方公众号,可快速关注) 关于人工智能未来的畅想,除了家庭服务机器人,快递无人机,医用机器人等等,Lucas Carlson 认为人工智能在另外一个领域 ...
- ES6中的数组
数组是js中很重要的数据类型,虽然在 ES5 中,关于数组的方法和属性很多.但为了更加简洁.高效的操作数组,ES6 中又在数组原型上和实例上新增了一些方法. 一.Array方法 1.1 Array.f ...
- C++扬帆远航——3(打印图形)
/* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:tuxing.cpp * 作者:常轩 * 完成日期:2016年3 ...
- 云机器同步数据 - rsync
一.需求 从google cloud云机器上定期同步图片内容,选用了支持增量备份的rsync. 二.rsync概述 rsyn是类unix系统下的数据镜像备份工具 - remote sync,安全性高, ...
- 脚本化处理linux云服务器第二硬盘初始化
#!/usr/bin/bash # 可以带参数 method=$ size=$ mydir=$ [ $#== ]&&{ echo -e "Missing parameter! ...
- sublime Text3 前端常用插件
sublime Text3 前端常用插件 - File Switching (文件切换) --- Sublime Text提供了一个非常快速的方式来打开新的文件.只要按下Ctrl+ P并开始输入你想要 ...
- psql的jsonb操作--存储对象/对象数组
1. 建表 create table demo( id serial NOT NULL PRIMARY KEY, name ), info JSONB ); 2.存储对象操作 2.1添加 insert ...
- 使用selenium模拟登陆淘宝、新浪和知乎
如果直接使用selenium访问淘宝.新浪和知乎这些网址.一般会识别出这是自动化测试工具,会有反制措施.当开启开发者模式后,就可以绕过他们的检测啦.(不行的,哭笑) 如果网站只是对windows.na ...
- Effective Go中文版(更新中)
原文链接:https://golang.org/doc/effective_go.html Introduction Go是一种新兴的编程语言.虽然它借鉴了现有语言的思想,但它具有不同寻常的特性,使得 ...






