2 questions are not correct, the method of seeking improvement

Source: Internet
Author: User

Randomly generates integers between 12 5~15 into a bunch of arrays, and then outputs these integers with 4 numbers per line

#include <stdio.h>
int main ()
{
int a[12],i,j;
for (i=0;i<11;i++)
scanf ("%d", &a[i]);
for (i=0;i<2;i++)
for (j=0;j<2;j++)
printf ("%d%d%d\n", a[i],a[i+1],a[i+2],a[i+3]);
}

Positive solution

#include <stdio.h>
Main ()
{
int a,i,j,n,b,s[120];
for (i=0;i<12;i++)
scanf ("%d", &s[i]);
for (i=0;i<12;i++)
{if (i%4==0)
printf ("\ n");
printf ("%d", s[i]);
}
return 0;
}

Use an array to find the average of the maximum minimum value of a set of numbers and how many more than the average

#include <stdio.h>
int main ()
{
int a[50],i,j,k=0,t,v,n;
scanf ("%d\n", &n);
for (i=0;i<n;i++)
scanf ("%d", &a[i]);
for (j=1;j<=n-1;j++)
{
for (i=0;i<=n-1;i++)
for (i=0;i<=n-j-1;i++)
if (a[i]>a[i+1])
{T=a[i];
A[I]=A[I+1];
a[i+1]=t;
}
}
for (i=0;i<n;i++)
T+=a[i];
v==t/(n);
for (i=0;i<n;i++)
{
if (V>a[i]);
}k+=1;
printf ("max=%d min=%d%d%d", a[i],a[0],v,k);
}

Positive solution

#include <stdio.h>
Main ()
{
int a=0,b,n,i,j,s[100],max,min,w;
scanf ("%d", &n);
w=0;
for (i=0;i<n;i++)
scanf ("%d", &s[i]);
Max=s[0];
for (i=1;i<n;i++)
if (Max<s[i])
Max=s[i];
else {max=s[i+1];min=s[i];}}
Min=s[0];
for (i=1;i<n;i++)
if (Min>s[0])
Min=s[i];
for (i=0;i<n;i++)
W=w+s[i];
w=w/n;
for (i=0;i<n;i++)
if (s[i]>w)
a++;
printf ("%d%d%d%d\n", max,min,w,a);
return 0;

}

2 questions are not correct, the method of seeking improvement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.