赞
踩
本题要求编写程序,找出给定的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; }
本题要求编写程序,对于给定的整数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; }
本题要求编写程序,计算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;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。