C Language 1.8 Review Problems

 

  1. Input 2 a positive number and n, find a + aa + aaa + ...... + a (n th a) the sum;

       2 + 22 + 222 + 2222 + 22222 (in this case n-=. 5 , A = 2 )

#include<stdio.h>
int main()
{
       int t,a,n,s,i;
       s=0;
       t=0;
       printf("请输入一个n:");
       scanf("%d",&n);
       printf("请输入一个a:");
       scanf("%d",&a);
       for(i=1;i<=n;i++)
       {
              t=t*10+a;
              s=s+t;
              printf("%d+",t);
       }
       printf("\b=%d\n",s);
}
  1. Initializing one-dimensional array, it is determined prime number (function), and the prime factors of a number of output;

  1. Number of daffodils, finished number;
#include <stdio.h>
int main()
{
	int i,a,b,c;
	for(i=100;i<=999;i++)
	{
		a=i/100;
		b=i%100/10;
		c=i%10;
		if(i==(a*a*a+b*b*b+c*c*c))
		{
			printf("%d ",i);
		}
	}
}
完数 
#include <stdio.h>
int main()
{
	int i,n,sum;
	for(n=1;n<=1000;n++)
{
	sum=0;
	for(i=1;i<=n/2;i++)
	{
		if(n%i==0)
		{
			sum+=i;
		}
	}
	if(n==sum)
{
	printf("%d ",n);
	printf("\n");
}
}	
}
  1. Bubble sort, selection sort;

bubble----- 

select---

Half -

https://blog.csdn.net/ao_mike/article/details/102837833

An integer that determines the number of bits of this number, the sum of the digits, and the number of reverse order output;

#include<stdio.h>
main()
{
int n,i,sum=0,count=0,temp=0; 
printf("请输入n的值:");
scanf("%d",&n);
for(i=n;i;i=i/10)
{
sum+=i%10;
temp=temp*10+i%10;
count++;
} 
printf("%d是%d位数\n",n,count);
printf("%d各位数之和是%d\n",n,sum);
printf("%d的逆序输出是%d\n",n,temp); 
}
//也可以用三个函数来写,记得函数原型声明 
int fun_ws(int n)
{
int i,count=0;
for(i=n;i;i=i/10)
count++; 
return count;
} 
int fun_wssum(int n)
{
int i,sum=0; 
for(i=n;i;i=i/10)
sum+=i%10; 
return sum;
} 
int fun_nx(int n)
{
int i,temp=0; 
for(i=n;i;i=i/10)
temp=temp*10+i%10; 
return temp;
}   
  1. Feibolaqi number of columns, and the fraction of sequences and extended therefrom; and interleaving sequence;
  2. ! Functions - recursion, n, and 1 + 2 + 3 + 4 + ... + n;
  3. if-else statement described piecewise function;
  4. Conditional expression, switch-case statement;
  5. Logical expression correlation output format, the input and output printf scanf needs attention;
  6. Euclidean greatest common divisor, least common multiple;
  7. Definition of the structure of an input and an output;
  8. The definition of a pointer, the output of the output, enabling the exchange of two numbers by a function;
  9. Array name as a function parameter usage;
  10. Custom function string compare implemented;
  11. Preprocessor: macros with parameters;
  12. Bitwise: bitwise and, bitwise or, bitwise exclusive OR, bitwise, left shift operator, a right shift operation;
  13. The new list, add nodes, delete nodes;

Other details please on their own review.

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

Guess you like

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