#include <stdio.h>
#include <stdlib.h>
int IsPrime(int num)
{
int i= 2;
if(num ==1) //1既不是质数也不是合数
return 0;
for(;i<= num /2;i++) //或者是for(;i<num;i++)
{
if(num %i==0) //not the Prime
return 0;
}
return 1;
}
void test()
{
int j=1;
int count=0;
for(;j<=100;j++)
{
if(IsPrime(j)==1)
{
count++;
printf( "%d ",j);
}
}
printf( "\nthe total of Prime in 1-100 is: %d\n" ,count);
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void test()
{
int a=0, b=0;
int i=0, j=0;
scanf( "%d%d", &a, &b);
if(a<b) //swap the num,to be sure a is the max num
{
i=a;
a=b;
b=i;
}
while(a%b!=0)
{
j=a%b;
a=b;
b=j; //余数保存在b中
}
printf( "the greatest common divisor is: %d\n" , b);
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void test()
{
int a=0, b=0;
int i=1;
scanf( "%d%d", &a, &b);
while(!(i%a==0 && i%b==0))
{
i++;
}
printf( "least common divisor is: %d\n" , i);
/*for(i=1;;i++)
{
if(i%a==0&&i%b==0)
{
printf("least common divisor is: %d\n", i);
break;
}
}*/
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void test()
{
int a=0, b=0;
int c=0;
scanf( "%d%d", &a, &b);
printf( "a=%d, b=%d\n", a, b);
c= a;
a= b;
b= c;
printf( "a=%d, b=%d\n", a, b);
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void swap(int * i, int* j)
{
int tmp= *i ;
* i= *j ;
* j= tmp;
}
void test()
{
int a=0, b=0;
scanf( "%d%d", &a, &b);
printf( "a=%d, b=%d\n", a, b);
swap(&a, &b);
printf( "a=%d, b=%d\n", a, b);
}
int main()
{
test();
system( "pause");
return 0;
}