当前位置:网站首页>C language 005: common examples
C language 005: common examples
2022-07-07 23:59:00 【Cloth scholar Python】
3、 ... and 、 Program analysis questions
1、 When a=1,b=3,c=5,d=4 when , After executing the following procedure x What's the value of ?
#include<stdio.h>
void main()
{
int a=1,b=3,c=5,d=4,x;
if(a<b)
if(c<d)
x=1;
else if (a<c)
if(b<d) x=2;
else x=3;
else x=6;
else x=7;
printf("%d",x);
return ;
}
answer :2
2、 For the following recursive functions f, call f(4), Its return value is ?
#include<stdio.h>
void main()
{
printf("%d",f(4));
return ;
}
int f(int n)
{
if(n>=1) return f(n-1)+n;
else return n;
}
answer :10
3、 When performing the following procedure , If input abc, Then the output of the following program is ?
#include<stdio.h>
void main()
{
char s[20]="12345";
scanf("%s",s);
strcat(s,"6789");
printf("%s\n",s);
return ;
}
answer :abc6789
4、 The output of the following program is ?
#include<stdio.h>
void main()
{
int a[6]={
1,2,3,4,5,6},i,s=0;
for(i=0;i<6;i++)
s+=a[i];
printf("%d\n",s);
return ;
}
answer :21
Four 、 Calculation questions
1、 Through the bubble sorting algorithm on the array int a[8] ={25,24,12,76,101,96,28,-1} Sort , requirement : Draw the first trip 、 The state of the array after the second sorting .
Refer to the answer :
2、 Use the half search method in the integer sequence {-1, 3 ,5 ,6 , 8 ,12, 32, 56, 85, 95, 100} Find the number in 10, Try to draw a picture, analyze and find the process .
Refer to the answer :
5、 ... and 、 Programming problem
1、 Programming questions . Enter a character , Judge whether it is a capital letter 、 Lowercase letters 、 Numbers or other .
Refer to the answer :
#include<stdio.h>
int main()
{
char ch;
while((ch=getchar())!=EOF){
if(ch>='A'&& ch<='Z')
printf(" It's capital letters !\n");
else if(ch>='a'&& ch<='z')
printf(" It's lowercase !\n");
else if(ch >='0'&& ch<='9')
printf(" It's the number. !\n");
else
printf(" It's something else !\n");
getchar();
}
return ;
}
2、 Programming questions . Input from keyboard 10 Number , Output its minimum and maximum values .
#include<stdio.h>
int main()
{
int arr[10];
int i,max,min;
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
max=arr[0];
min=arr[0];
for(i=1;i<10;i++){
if(arr[i]>max)
max=arr[i];
if(arr[i]<min)
min=arr[i];
}
printf(" minimum value :%d, Maximum :%d\n",min,max);
return 0;
}
3、 Programming questions . Write a function to determine prime numbers , stay main The function is called in the function , Output 100 All prime numbers within .
Refer to the answer :
#include<stdio.h>
int su_shu(int n){
int i;
if(n==1)
return 0;
for(i=2;i<=n;i++){
if(n%i==0&&n!=i)
return 0;
if(n==i)
return 1;
}
}
int main()
{
int i;
for(i=1;i<100;i++){
if(su_shu(i)==1)
printf("%d\t",i);
}
return 0;
}
4、 Programming questions . Write function mystrcmp( The formal parameter is a pointer ), Used to determine the greater than... Between two strings 、 Less than or equal to .
Refer to the answer :
#include<stdio.h>
int mystrcmp(const char *str1,const char *str2){
while(*str1==*str2)
{
if(*str1=='\0'&&*str2=='\0')
return 0;
str1++;
str2++;
}
if(*str1>*str2)
return 1;
if(*str1<*str2)
return -1;
}
int main()
{
char str1[100],str2[100];
scanf("%s",str1);
scanf("%s",str2);
int i=mystrcmp(str1,str2);
if(i==0)
printf(" String equality \n");
if(i==1)
printf(" character string 1 Greater than string 2\n");
if(i==-1)
printf(" character string 1 Less than string 2\n");
return 0;
}
边栏推荐
- Archery installation test
- HB 5469 combustion test method for non-metallic materials in civil aircraft cabin
- Robomaster visual tutorial (1) camera
- P2141 [noip2014 popularization group] abacus mental arithmetic test
- Postgres timestamp to human eye time string or millisecond value
- Go learning notes (1) environment installation and hello world
- 80%的人答错,苹果logo上的叶子到底朝左还是朝右?
- P1308 [noip2011 popularity group] count the number of words
- Using Google test in QT
- At the age of 35, I made a decision to face unemployment
猜你喜欢

【編程題】【Scratch二級】2019.12 飛翔的小鳥

Go learning notes (1) environment installation and hello world

10 schemes to ensure interface data security

Introduction to programming hardware

How did a fake offer steal $540million from "axie infinity"?

FFA and ICGA angiography

35岁那年,我做了一个面临失业的决定

【史上最详细】信贷中逾期天数统计说明

HB 5469 combustion test method for non-metallic materials in civil aircraft cabin

80%的人答错,苹果logo上的叶子到底朝左还是朝右?
随机推荐
The result of innovation in professional courses such as robotics (Automation)
Kubectl's handy command line tool: Oh my Zsh tips and tricks
CoinDesk评波场去中心化进程:让人们看到互联网的未来
【史上最详细】信贷中逾期天数统计说明
QT creator add custom new file / Project Template Wizard
【编程题】【Scratch二级】2019.03 垃圾分类
STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
自动化测试:Robot FrameWork框架90%的人都想知道的实用技巧
At the age of 35, I made a decision to face unemployment
Chisel tutorial - 00 Ex.scala metals plug-in (vs Code), SBT and coursier exchange endogenous
蓝桥ROS中使用fishros一键安装
Pigsty: out of the box database distribution
SQL uses the in keyword to query multiple fields
HDU - 1260 tickets (linear DP)
Kubectl 好用的命令行工具:oh-my-zsh 技巧和窍门
Install sqlserver2019
ROS从入门到精通(九) 可视化仿真初体验之TurtleBot3
一键免费翻译300多页的pdf文档
AITM3.0005 烟雾毒性测试
一份假Offer如何盗走了「Axie infinity」5.4亿美元?