当前位置:   article > 正文

2021.3.28_输入在第一行中给出一个正整数n(1

输入在第一行中给出一个正整数n(1

本题要求编写程序,找出给定的n个数中的最小值及其对应的最小下标(下标从0开始)。
输入格式:
输入在第一行中给出一个正整数n(1≤n≤10)。第二行输入n个整数,用空格分开。
输出格式:
在一行中输出最小值及最小值的最小下标,中间用一个空格分开。
输入样例:
6
2 9 -1 8 -1 6
输出样例:
-1 2

#include<stdio.h>
int main()
{
    int n,i,index;
    scanf("%d",&n);
    int a[n];
    scanf("%d",&a[0]);
    index=0;
    for(i=1;i<n;i++)
    {
      scanf("%d",&a[i]);
      if(a[index]>a[i])
       {
          index=i;
       }
    }
    printf("%d %d",a[index],index);
    return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

本题要求编写程序,对于给定的整数N,求它的位数。
输入格式:
输入在一行中给出一个绝对值不超过10
​9
​​ 的整数N。
输出格式:
在一行中输出N的位数。
输入样例1:
12534
输出样例1:
5

#include <stdio.h>
#include <math.h>
int main()
{
    long int N;
    int count=0;
    scanf("%ld",&N);
    do{
        count++;
        N=N/10;
    }
    while(N!=0);
    printf("%d\n",count);
    return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

本题要求编写程序,计算N的阶乘。
输入格式:
输入在一行中给出一个不超过12的正整数N。
输出格式:
在一行中输出阶乘的值

#include<stdio.h>
int main()
{
    int i,N;
    int fact=1;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        fact = fact * i;
    }
    printf("%d\n",fact);
    return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/293046
推荐阅读
相关标签