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. 2020 倒计时 1 天,Python 工程师找工作更难了?

    Python 是最神奇的编程语言. 无意引战,我说的是"神奇",不是"最好",并不想去"撼动" PHP 的地位.               ...

  2. 详解服务器性能测试的全生命周期?——从测试、结果分析到优化策略(转载)

    服务器性能测试是一项非常重要而且必要的工作,本文是作者Micheal在对服务器进行性能测试的过程中不断摸索出来的一些实用策略,通过定位问题,分析原因以及解决问题,实现对服务器进行更有针对性的优化,提升 ...

  3. Logback 标准xml参考

    强制: [强制]应用中不可直接使用日志系统(Log4j.Logback)中的 API,而应依赖使用日志框架SLF4J 中的 API,使用门面模式的日志框架,有利于维护和各个类的日志处理方式统一.imp ...

  4. 机器学习 —— 数据预处理

    对于学习机器学习算法来说,肯定会涉及到数据的处理,因此一开始,对数据的预处理进行学习 对于数据的预处理,大概有如下几步: 步骤1 -- 导入所需库 导入处理数据所需要的python库,有如下两个库是非 ...

  5. 工业界 vs. 学术界: 一个年轻员工的视角

    本文发表于<中国计算机学会通讯>2015年第5期,转载已获得授权 作者:菲利普·郭 (Philip Guo),美国罗切斯特大学助理教授 译者:​王长虎,微软亚洲研究院主管研究员 如果你即将 ...

  6. [Python_scrapy图片爬取下载]

    welcome to myblog Dome地址 爬取某个车站的图片 item.py 中 1.申明item 的fields class PhotoItem(scrapy.Item): # define ...

  7. 天哪!毫无思绪!令人感到恐惧的数学(水题?)(TOWQs)

    这道题的题目描述灰常简单,第一眼看以为是一道十分水的题目: 但是!!!(我仔细一看也没有发现这背后隐藏着可怕的真相~) 下面给出题目描述: 给出一个整数x,你可以对x进行两种操作.1.将x变成4x+3 ...

  8. Wordpress 外网访问时不显示图片解决办法

    我的云服务器是 :windows2012R 打开命令行: 进入到mysql中 show databases; //查看你Wordpress使用的数据库是否存在 use blog; //例如你使用的数据 ...

  9. 1,Java知识储备

    1,关于 . java文件 规定:第一行为 package name; 表示该.java文件属于哪一个包. 一个.java文件中可以有多个类,但是只能有一个public类,并且这个public类必须与 ...

  10. 浅析TCP/IP协议

    浅析TCP/IP协议 0x00 什么是TCP/IP协议? ​ 想一想人与人之间交流需要什么?我们是不是要掌握一种我们都能体会到对方意思的语言.那么计算机与网络设备之间进行通信,是不是不同设备之间是不是 ...