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. kettle_errot_karafLifecycleListenter

    使用kettle 6.1 通过命令行批量执行作业的过程中,发现偶尔有作业执行时间会变慢几分钟,查看日志发现改作业开始就报了一个错 报错之后才会继续下面的作业,虽然不影响最终作业执行结果,但也延误了一些 ...

  2. 你会选永生吗?NASA实验为火星宇航员提供年龄逆转药

    ​​宇宙辐射不仅是宇航员面临的问题.在乘坐飞机的过程中,我们所有人都会暴露在宇宙辐射中.一趟从伦敦到新加坡再到墨尔本的飞行中,人体受到的辐射量就相当于进行一次胸部X射线透视. ​在去年12月NASA举 ...

  3. Circles of Waiting

    题目传送门 很容易列出期望的方程,高斯消元搞一波但是常规消元复杂度是$O(r^6)$的考虑从左到右从上到下编号然后按编号从小到大消元假设黄点是已经消元的点,那么消下一个点的时候,只有绿点的方程中该项系 ...

  4. CSS——NO.1(初识CSS)

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

  5. 微信h5页面audio标签在ios下不能自动播放

    背景介绍:在一个h5页面中,当用户提交表单到后台,后台返回的结果成功的话,开始自动播放背景音乐 出现的问题:在安卓手机上正常,iOS中没有反应 后来网上一番搜索后了解到时因为iOS不允许自动播放音乐, ...

  6. 对HTML语义化的一些理解和记录

    什么是HTML语义化 说HTML语义化就要先说说HTML到底负责的什么?下面摘自维基百科: 超文本标记语言(英语:HyperText Markup Language,简称:HTML)是一种用于创建网页 ...

  7. 论nw.js的坑~~~感觉我所有的前端能遇到的坑都踩了一遍

    先总结:nw.js 真特么的...难用...文档,我得先百度才能看的稍微明白点文档......!!!!!!我感觉我所有的前端能遇到的坑都踩了一遍,此文针对前后端分离项目,别的先不说 一.不需要在项目里 ...

  8. 2020ubuntu1804server编译安装redis5笔记(二)配置redis

    前一篇笔记记录了ubuntu1804server编译安装redis5,接下来要配置redis5了 网址:https://www.cnblogs.com/qumogu/p/12435694.html 第 ...

  9. WEB渗透 - 万能密码

    asp万能密码 'or'='or' aspx万能密码 1: "or "a"="a 2: ')or('a'='a 3:or 1=1-- 4:'or 1=1-- 5 ...

  10. chrome安装扩展插件出现-crx_header_invalid问题

    1. 将*.crx文件重命名为*.rar 2.将rar文件解压 3. 在chrome浏览器添加扩展程序时选择“加载已解压的扩展程序” 4.添加成功