Control structure and statements (while for if)

 

 

Truck traffic violation, after the butt escape. Three people witnessed the scene of the incident, but did not remember the license plate number, just remember some of the features of the license plate number. A says: The first two digits are the same license plate number; B says: the last two digits are the same license plate number, but different from the first two; prop was a mathematician who said: car number 4 just is an integer squared. Based on the above, please help police find clues program number, in order to solve the case as soon as possible, to seize the traffic accident guilty.
Range of control

Named the range of control variables

The value of m column Why is 3-k

+ Nested loops used in the frame number

 

 

 

 

6. The first three columns are known in a number of 0,0,1, which are adjacent after the first three sum. And outputs the calculated sum of squares of the item when the sum n number of columns.

 

#include<stdio.h>
#include<math.h>
int main()
{
    int fn,f1,f2,f3,s,n,i;
    double x;
    f1=0;
    f2=0;
    f3=1;
    s=0;
    scanf("%d",&n);
    for(i=4;i<=n;i++)
    {
        fn=f1+f2+f3;
        s+=fn;
        f1=f2;
        f2=f3;
        f3=fn;
}
    s=s+1;
    x=sqrt(s*1.0);
    printf("%d\n",s);
    printf("%f\n",x);
    printf("%d\n",fn);
}

Output data% d is shaped like columns of the Fibonacci FIG draw out ideas 

 

7. The number of programming, input integer 10, wherein the statistics and write a positive, negative, 0

#include<stdio.h>
int main()
{
	int i,j,k,n,c,d;
	c=0;
	d=0;
	k=0;
	for(i=1;i<=10;i++)
	{
		scanf("%d",&n);
	if(n>0)
	{
		c++;
	}
	else if(n<0) 
	{
		d++;
	}
	else
	{
		k++;
	}
	}
	printf("正=%d\n",c);
	printf("负=%d\n",k);
	printf("0=%d\n",d);
}

Anyway, I will not do too much food 

 

8. Operator sum y


Or problem moderation.

#include<stdio.h>
int main()
{
	int i,n;
	double y,s;
	i=1;
	s=0;
	y=1;
	while(y>1e-6)
	{
		y=1.0/((i*i)+1);
		s=s+y;
		i++;
	}
	printf("y=%f\n",y); 
	printf("%f",s); 
}

9.

 

#include<stdio.h>
void main(){
 int year,month;
 int flag=0;
 printf("请输入年 月: ");
 scanf("%d %d",&year,&month);
 if(year%4==0&&year%100!=0||year%400==0)
 flag=1;  //是闰年
 switch(month){
 case 1:
 case 3:
 case 5:
 case 7:
 case 8:
 case 10:
 case 12:
  printf("31 days\n");
  break;
 case 2:
  if(flag==1)
   printf("29 days\n");
  else
   printf("28 days\n");
  break;
 case 4:
 case 6:
 case 9:
 case 11:
  printf("30 days\n");
  break;
 }

10.6-10000 intimate number of

#include<stdio.h>
int main()
{
int a,i,b,n;
printf("There are following friendly--numbers pair smaller than 10000:\n");
for(a=6;a<10000;a++) /*穷举10000以内的全部整数*/
{
for(b=0,i=1;i<=a/2;i++) /*计算数a的各因子,各因子之和存放于b*/
if(!(a%i)) b+=i; /*计算b的各因子,各因子之和存于n*/ //a/2 适用于因子比对 
for(n=0,i=1;i<=b/2;i++)    //一般傻逼做题会考虑从i,但这边从a中内嵌b考虑,更简洁 
if(!(b%i)) n+=i;       //!(b%i)== b%i==0 
if(n==a&&a!=b)
printf("%4d....%4d\n",a,b); /*若n=a,则a和b是一对亲密数,输出*/
}
}

Take a look at comments, questions were very interesting, you think of something, or too little, too look at the subject of grass.

 

Published 57 original articles · won praise 27 · views 10000 +

Guess you like

Origin blog.csdn.net/ao_mike/article/details/102768235