- 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);
}
- Initializing one-dimensional array, it is determined prime number (function), and the prime factors of a number of output;
- 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");
}
}
}
- 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;
}
- Feibolaqi number of columns, and the fraction of sequences and extended therefrom; and interleaving sequence;
- ! Functions - recursion, n, and 1 + 2 + 3 + 4 + ... + n;
- if-else statement described piecewise function;
- Conditional expression, switch-case statement;
- Logical expression correlation output format, the input and output printf scanf needs attention;
- Euclidean greatest common divisor, least common multiple;
- Definition of the structure of an input and an output;
- The definition of a pointer, the output of the output, enabling the exchange of two numbers by a function;
- Array name as a function parameter usage;
- Custom function string compare implemented;
- Preprocessor: macros with parameters;
- Bitwise: bitwise and, bitwise or, bitwise exclusive OR, bitwise, left shift operator, a right shift operation;
- The new list, add nodes, delete nodes;
Other details please on their own review.