#include<stdio.h> int main() { int i; double average,sum=0; int a[10]; printf("Enter 10 integers:"); for(i=0;i<10;i++){ scanf("%d",&a[i]); sum=sum+a[i]; } average=sum/10; printf("average=%.2f\n",average); printf("sum=%.2f\n",sum); return 0; }
#include<stdio.h> int main() { int i,flag,x; int a [5]; printf("enter 5 integers:"); for(i=0;i<=5;i++) scanf("%d",&a[i]); printf("enter x:"); scanf("%d",&x); flag=0; for(i=0;i<5;i++) if(a[i]==x){ printf("index is %d\n",i); flag=1; break; } if(flag==0) printf("not found\n"); return 0; }
#include<stdio.h> int main() { int i,index,n; int a[10]; printf("enter n(1<n≤10):"); scanf("%d",&n); printf("enter %d intergers:",n); for(i=1;i<=n;i++){ scanf("%d",&a[i]); } for(i=1;i<=n;i++) if (a[i]>a[index]) index=i; printf("min is %d\tsub is %d\n",a[index],index); return 0; }
#include<stdio.h> int main() { int i,index,j,n,temp; int a[10]; printf("entern n(1<n≤10):"); scanf("%d",&n); printf("enter %d integers:",n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(j=0;j<n-1;j++) { index=j; for(i=j+1;i<n;i++) if(a[i]>a[index]) index=i; temp=a[index]; a[index]=a[j]; a[j]=temp; } printf("after sorted:"); for(i=0;i<n;i++) printf("%d",a[i]); printf("\n"); return 0; }
时间: 2024-10-10 12:47:23