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. STM32 一个初始化EXTI的例子

    23 May 2017 » Hardware 注:STM32F407VGT6 with STM32F4 DSP and standard peripherals library v1.8.0 外部中断 ...

  2. first-child和first-of-type

    我想实现的效果:将第一个article字体颜色设置为红色 123456 <div? <h1>logo</h1> <article>article1</a ...

  3. 一起了解 .Net Foundation 项目 No.8

    .Net 基金会中包含有很多优秀的项目,今天就和笔者一起了解一下其中的一些优秀作品吧. 中文介绍 中文介绍内容翻译自英文介绍,主要采用意译.如与原文存在出入,请以原文为准. IdentityModel ...

  4. C++走向远洋——60(项目四、立体类族共有的抽象类)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  5. 后渗透之meterpreter使用攻略

    Metasploit中的Meterpreter模块在后渗透阶段具有强大的攻击力,本文主要整理了meterpreter的常用命令.脚本及使用方式.包含信息收集.提权.注册表操作.令牌操纵.哈希利用.后门 ...

  6. 对象深拷贝deepCopy

    function type(obj){ return Object.prototype.toString.call(obj).slice(8,-1); } function deepCopy(targ ...

  7. 从头认识js-DOM1

    前面说过一个完整的js实现,包括ECMAScript,BOM,DOM三部分,现在就来讲讲DOM的有关知识. DOM(文档对象模型)是针对HTML和XML文档的一个API(应用程序接口).DOM描绘来一 ...

  8. Swagger默认访问地址

    Springboot工程格式 http://localhost:8080/swagger-ui.html 非Springboot工程格式(需加个项目名xxx) http://localhost:808 ...

  9. Vue2.0组件的继承与扩展

    如果有需要源代码,请猛戳源代码 希望文章给大家些许帮助和启发,麻烦大家在GitHub上面点个赞!!!十分感谢 前言 本文将介绍vue2.0中的组件的继承与扩展,主要分享slot.mixins/exte ...

  10. 盘点Mac上搭建本地WebServer的几种方式

    第一种: 通过Nginx搭建本地WebServer 安装nginx brew install nginx 安装完后在终端输入nginx指令,启动nginx查看效果 确定安装好之后,在根目录创建一个文件 ...