zl程序教程

您现在的位置是:首页 >  后端

当前栏目

两道C语言题目

C语言 题目 两道
2023-06-13 09:15:18 时间

1:给定一个升序排列的数组,要求插入一个新数据后仍然升序输出,例如:原数据为:1,6,9,23,56,95插入新的一个数据50后输出变为:1,6,9,23,50,56,95.

算法(个人答案):

#include "stdio.h"
#include "windows.h"


void main(int argc, char* argv[])
{
int inputno,m,j,k,i;
int a[7]={1,6,9,23,56,95};
printf("Source number:\n");
for ( m=0;m<7;m++){
            printf("%d  ",a[m]);
        }
printf("\nPlease input ur number:\n");
scanf("%d",&inputno);
a[6]=inputno;
for ( i=0;i<7 ;i++)
    {
        if( (a[6]>a[i]) && (a[6]i+1;j--){
                a[j]=a[j-1];
                }
                a[i+1]=inputno;
        }
    }
for ( k=0;k<7;k++){
        printf("%d  ",a[k]);
    }
    //Sleep(10000);
}

2:打印一个图案,要求中间一排为“+”,例如:输入5时输出为:

算法(个人答案):

#include 
#include 
void main()
{
    int inputlines,i,j;
    printf("Please insert ur inputlines to type:\n");
    scanf("%d",&inputlines);
    printf("Output is like this:\n");
    for (i=0;i



☆文章版权声明☆
* 网站名称:obaby@mars

 * 网址:https://h4ck.org.cn/

  * 本文标题: 《两道C语言题目》
      * 本文链接:https://h4ck.org.cn/2010/03/c-topic/
      * 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。
    


分享文章:

相关文章:
C语言二维数组 打印方阵 
一道C++题{字符串处理} 
Hooking library calls on Mac using DYLD_INSERT_LIBRARIES 
WSock32 Hook send and recv Functions 
Using NSTask in iOS Console Application 
WMI Based System Share Detect Via C/C++ 
Windows 7/Visual Studio2012下使用GTK 
C语言:字符串详解 
Windows HotFix Check Via C/C++ 
EasySYS 0.3.2.6 for vs2008/WDK7