1.输出:9 6
#include<stdio.h>
int main()
{
int x=1,y=2;
for( ; x<10 ; x++)
{
x+= 2;
if ( x>7 ) break;
if ( x==6 ) continue;
y *= x;
}
printf("%d %d\n",x,y);
return 0;
}
2.输出2 6 42 3
#include <stdio.h>
int Square(int i)
{
return i * i;
}
int main( )
{
int i = 0;
i = Square(i);
for( ; i<3; i++)
{
static int i = 1;
i += Square(i);
printf("%d ", i);
}
printf("%d\n", i);
return 0;
}
3.输出 1 1
#include <stdio.h>
void swap(int *a, int b)
{
int m, *n;
n=&m;
*n=*a;
*a=b;
b=*n;
}
int main()
{
int x=8,y=1;
swap(&x,y);
printf("%d %d\n",x,y);
return 0;
}
4.11 22 33 0
#include<stdio.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node array[4]={{11},{22},{33}}, *p;
for( p=array ; p<array+3 ; p++ )
p->next = p+1;
p->next = 0;
p=array;
while ( p != '\0' )
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
return 0;
}
5.输出:20101622
#include <stdio.h>
void fun(char str[ ])
{
int i,j;
for (i=0,j=0;str[i];i++)
if ( str[i]>='0'&&str[i]<='9') str[j++]= str[i];
str[j]='\0';
}
int main()
{
char str[100]="By the end of February of 2010, the total number of the teaching staff in
NUPT has reached 1622.";
fun(str);
printf("%s\n",str);
return 0;
}
6.输出11 13 17 19
#include<stdio.h>
#include <stdio.h>
#include <math.h>
int main( )
{ int i,j,k;
for (i=11;i<20;i=i+2)
{
k=(int)sqrt(i);
for (j=2;j<=k;j++)
if (!(i%j)) break;
if (j>k) printf("%d,",i);
}
return 0;
}
sqrt()函数的返回值是 double型。
7.输出3,4,1,3,6,2,
#include <stdio.h>
int x;
void f1( );
void f2(int);
int main( )
{
int i;
for (i=1;i<=2;i++)
{ x++;
f1( );
f2(x);
printf("%d,",x);
}
return 0;
}
void f1( )
{
int x=3;
printf("%d,",x++);
}
void f2(int y)
{ static int x=3;
printf("%d,",y+x);
x++ ; y++ ;
}
8.输出:max=12,min=72
#include<stdio.h>
gcd(int p,int q)
{
if(p==q) return p;
else if(p>q )return gcd(p-q,q);
else return gcd(p,q-p) ;
}
int main()
{
int m=24,n=36,min,max;
max=gcd(m,n);
min=m*n/max;
printf("max=%d,min=%d\n",max,min);
return 0;
}
9.输出3
#include <stdio.h>
int Cube(int i)
{
return i * i*i; }
int main( ) {
int i = 0;
i =Cube(i);
for( ; i<3; i++)
{
static int i = 1;
i +=Cube(i);
}
printf("%d\n", i);
return 0;
}
10输出:edgrey
#include<stdio.h>
#include<string.h>
int main( )
{
char *p;
char color1[10]= "red",color2[10]= "grey";
p=color1;
p++;
strcat(p,color2);
printf("%s\n",p);
return 0;
}
11.输出:3,wang,2.67
#include<stdio.h>
#include<string.h>
struct st
{ int x;
char str[10];
float y;
};
void func(struct st *b)
{
b->x=3;
strcpy( b->str, "wang");
b->y /= b->x;
}
int main( )
{
struct st a = { 10 , "x" , 8.0 } , *p = &a;
func( p );
printf( "%d , %s , %5.2f\n" , a.x , a.str , a.y);
return 0;
}