C语言试题记录

原创 2018年04月17日 15:18:57

C语言试题记录

一、图形

1-1 输出平行四边形**

                   **

#include <stdio.h>

int main()

{ int i,j,k,n;

         scanf("%d",&n);

         for(i=1;i<=n;i++)

                  {       for (j=1;j<=i-1;j++)

                          printf(" ");

                          for(k=1;k<n;k++)

                          printf("*");

                          printf("*\n");

                 

                  }

         return0;

}

1-2 输出平行四边形 **

                  **

#include <stdio.h>

int main()

{ int i,j,k,n;

         scanf("%d",&n);

         for(i=1;i<=n;i++)

                  {       for (j=1;j<=n-i;j++)

                          printf(" ");

                          for(k=1;k<n;k++)

                          printf("*");

                          printf("*\n");

                 

                  }

         return0;

}

1-3输出三角形 ***

               *

#include <stdio.h>

int main()

{ int n,i,j,k;

         scanf("%d",&n);

         for(i=1;i<=n;i++)

         {for (j=1;j<=i-1;j++)

                  printf(" ");

           for (k=1;k<2*(n-i)+1;k++)

             printf ("*");

             printf ("*\n");

         }

         return0;

}

1-4 输出三角形 *

              ***

#include <stdio.h>

int main()

{ int n,i,j,k;

         scanf("%d",&n);

         for(i=1;i<=n;i++)

         {for (j=1;j<=n-i;j++)

                  printf(" ");

           for (k=1;k<2*i-1;k++)

             printf ("*");

             printf ("*\n");

         }

         return0;

}

1-5 梯形****

        **

#include <stdio.h>

int main()

{       inti,j,k,n;

         scanf("%d",&n);

         for(i=1;i<=n;i++)

         {for (j=1;j<=i-1;j++)

                  printf(" ");

           for (k=1;k<2*(n-i+1)+1;k++)

             printf ("*");

             printf ("*\n");

         }

         return0;

}

1-6 梯形**

      ****

#include <stdio.h>

int main()

{       inti,j,k,n;

         scanf("%d",&n);

         for(i=1;i<=n;i++)

         {for (j=1;j<=n-i;j++)

                  printf(" ");

           for (k=1;k<2*i+1;k++)

             printf ("*");

             printf ("*\n");

         }

         return0;

}

1-7 菱形

#include <stdio.h>

int main(int argc, char** argv)

{

         inti,j,k,n;

         scanf("%d",&n);

         for(i=1;i<n;i++)

         {for(j=1;j<=n-i;j++)

         printf(" ");

         for(k=1;k<=2*i-1;k++)

         printf("*");

         printf("\n");

         }

         for(i=1;i<=n;i++)

         {for (j=1;j<=i-1;j++)

         printf(" ");

         for(k=1;k<=2*(n-i)+1;k++)

         printf("*");

         printf("\n");

         }

         return0;

}

1-8 正六边形

#include <stdio.h>

int main(int argc, char** argv)

{

         inti,j,k,n;

         scanf("%d",&n);

         for(i=1;i<n;i++)

         {for(j=1;j<=n-i;j++)

         printf(" ");

         for(k=1;k<=n+2*(i-1);k++)

         printf("*");

         printf("\n");

         }

         for(i=1;i<=n;i++)

         {for (j=1;j<=i-1;j++)

         printf(" ");

         for(k=1;k<=n+2*(n-i);k++)

         printf("*");

         printf("\n");

         }

         return0;

}

 

//输出这些实心图形的方法就是每一行先输出空格然后输出*最后换行

 

1-9之字形

#include<stdio.h>

intmain ()

{       int n,i,j;

         scanf ("%d",&n);

         for (j=0;j<n;j++)

         printf ("*");

         printf ("\n");

         for (i=1;i<n-1;i++)

                  {       for (j=1;j<=n-1-i;j++)

                          printf ("");

                          printf("*\n");

                  }

         for (j=0;j<n;j++)

         printf ("*");

         printf ("\n");

}

1-10之字形

#include<stdio.h>

intmain ()

{       int n,i,j;

         scanf ("%d",&n);

         for (j=0;j<n;j++)

         printf ("*");

         printf ("\n");

         for (i=1;i<n-1;i++)

                  {       for (j=1;j<=i;j++)

                          printf ("");

                          printf("*\n");

                  }

         for (j=0;j<n;j++)

         printf ("*");

         printf ("\n");

}

1-11空心三角形正

#include<stdio.h>

intmain()

{       int n,i,j;

         scanf ("%d",&n);

         for (i=1;i<n;i++)

                  {       for (j=1;j<=n-2+i;j++)

                          {

                                   if (i+j==n+1) printf ("*");

                                   else printf (" ");

                          }

                          printf("*\n");

                  }

         for (i=1;i<=2*n-1;i++)

         printf ("*");

         printf ("\n");

         return 0;

}      

1-12空心三角形反

#include<stdio.h>

intmain()

{       int n,i,j;

         scanf ("%d",&n);

         for (i=1;i<=2*n-1;i++)

                  printf ("*");

         printf ("\n");

         for (i=1;i<n;i++)

                  {       for (j=1;j<=2*(n-1)-i;j++)

                          {

                                   if (j==i+1) printf ("*");

                                   else printf (" ");

                          }

                          printf("*\n");

                  }

         return 0;

}

1-13空心平行四边形右边斜

#include<stdio.h>

intmain ()

{       int n,i,j;

         scanf ("%d",&n);

         for (j=1;j<=n;j++)

         printf ("*");

         printf ("\n");

         for (i=1;i<=n-2;i++)

         {       for(j=1;j<=i;j++)

                  printf (" ");

                  printf ("*");

                  for (j=1;j<n-1;j++)

                  printf (" ");

                  printf ("*\n");

         }

         for(j=1;j<n;j++)

         printf (" ");

         for (j=1;j<=n;j++)

         printf ("*");

         printf ("\n");

}

1-14空心平行四边形左边斜

#include<stdio.h>

intmain ()

{       int n,i,j;

         scanf ("%d",&n);

         for(j=1;j<n;j++)

         printf (" ");

         for (j=1;j<=n;j++)

         printf ("*");

         printf ("\n");

         for (i=1;i<=n-2;i++)

         {       for(j=1;j<=n-i-1;j++)

                  printf (" ");

                  printf ("*");

                  for (j=1;j<n-1;j++)

                  printf (" ");

                  printf ("*\n");

         }

         for (j=1;j<=n;j++)

         printf ("*");

         printf ("\n");

}

1-15空心等腰梯形

#include<stdio.h>

intmain()

{       int h,i,j;

         scanf ("%d",&h);

         for (j=0;j<h-1;j++)

         printf (" ");

         for (j=1;j<=h;j++)

         printf ("*");

         printf ("\n");

         for (i=1;i<=h-2;i++)

         {       for(j=1;j<=h-1-i;j++)

                  printf (" ");//输出字符前面的空格

                  printf ("*");

                  for (j=1;j<=h+2*(i-1);j++)

                  printf (" ");//空心部分字符

                  printf ("*\n"); 

         }

         for (j=1;j<=3*h-2;j++)

         printf ("*");

         printf ("\n");

}

1-16空心正六边形

#include<stdio.h>

intmain()

{       int h,i,j;

         scanf ("%d",&h);

         for (j=0;j<h-1;j++)

         printf (" ");

         for (j=1;j<=h;j++)

         printf ("*");

         printf ("\n");

         for (i=1;i<=h-1;i++)

                  {       for (j=1;j<=h-i-1;j++)

                          printf ("");

                          printf("*");

                          for(j=1;j<=h+2*(i-1);j++)

                          printf ("");

                          printf("*\n");

                  }

         for (i=1;i<=h-2;i++)

         {       for(j=1;j<=i;j++)

                  printf (" ");

                  printf ("*");

                  for(j=1;j<h+2*(h-1)-2*i-1;j++)

                  printf (" ");

                  printf ("*\n");

         }

         for (j=0;j<h-1;j++)

         printf (" ");

         for (j=1;j<=h;j++)

         printf ("*");

         printf ("\n");

}

1-17空心等腰#include <stdio.h>

intmain(int argc, char** argv)

{       int i,j,n;

         scanf ("%d",&n);

         for (i=1;i<=n+2*(n-1);i++)

         printf ("*");

         printf("\n");

         for (i=1;i<=n-2;i++)

                  {       for (j=1;j<=i;j++)

                          printf ("");printf ("*");

                          for(j=1;j<=n+2*(n-2-i);j++)

                          printf ("");printf ("*\n");

                  }

         for (j=1;j<=n-1;j++)

         printf (" ");

         for (j=1;j<=n;j++)

         printf("*");

         printf ("\n");

         return 0;

}

1-18空心菱形

#include<stdio.h>

intmain(int argc, char** argv)

{       int i,j,n;

         scanf ("%d",&n);

         for (i=1;i<=n-1;i++)

         printf (" ");

         printf("*\n");

         for (i=1;i<=n-1;i++)

                  {       for (j=1;j<n-i;j++)

                          printf ("");printf ("*");

                          for (j=1;j<=2*i-1;j++)

                          printf ("");printf ("*\n");

                  }

         for (i=1;i<=n-2;i++)

                  {       for (j=1;j<=i;j++)

                          printf ("");printf ("*");

                          for(j=1;j<=2*(n-1-i)-1;j++)

                          printf ("");printf ("*\n");

                  }

         for (i=1;i<=n-1;i++)

         printf (" ");

         printf("*\n");

         return 0;

}

1-19*    *

** **

******

#include <stdio.h>

int main(int argc, char** argv)

{        inti,j,n;

         scanf("%d",&n);

         for(i=1;i<=n-1;i++)

                  {       for (j=1;j<=i;j++)

                           printf("*");

                           for(j=1;j<=2*(n-i)-1;j++)

                           printf(" ");

                           for(j=1;j<=i;j++)

                           printf("*");

                           printf("\n");

                  }

         for(j=1;j<=2*(n-1)+1;j++)

         printf("*");

         printf("\n");    

         return0;

}

1-20                 *********

                    **** ****

                    ***   ***

                    **     **

                     *       *  

#include<stdio.h>

intmain(int argc, char** argv)

{       int i,j,n;

         scanf ("%d",&n);

         for (j=1;j<=2*(n-1)+1;j++)

         printf ("*");

         printf("\n");    

         for (i=1;i<=n-1;i++)

                  {       for (j=1;j<=n-i;j++)

                          printf("*");

                          for(j=1;j<=2*i-1;j++)

                          printf ("");

                          for(j=1;j<=n-i;j++)

                          printf("*");

                          printf("\n");

                  }     

         return 0;

}

1-21  X

#include<stdio.h>

intmain(int argc, char** argv)

{       int i,j,n;

         scanf ("%d",&n);

         for (i=1;i<=n-1;i++)

                  {       for (j=1;j<=i-1;j++)

                          printf ("");printf ("*");

                          for (j=1;j<=2*(n-i)-1;j++)

                          printf ("");printf ("*\n");

                  }

         for (i=1;i<=n-1;i++)

         printf (" ");

         printf("*\n");

         for (i=1;i<=n-1;i++)

                  {       for (j=1;j<n-i;j++)

                          printf ("");printf ("*");

                          for(j=1;j<=2*i-1;j++)

                          printf ("");printf ("*\n");

                  }

}

1-22  Y

#include<stdio.h>

intmain(int argc, char** argv)

{       int i,j,n;

         scanf ("%d",&n);

         for (i=1;i<=n-1;i++)

                  {       for (j=1;j<=i-1;j++)

                          printf ("");printf ("*");

                          for(j=1;j<=2*(n-i)-1;j++)

                          printf ("");printf ("*\n");

                  }

         for (i=1;i<=n;i++)

                  {       for (j=1;j<=n-1;j++)

                          printf ("");

                          printf("*\n");

                  }

}

1-23  K

#include<stdio.h>

intmain(int argc, char** argv)

{

         int i,j,k,n;

         scanf ("%d",&n);

         for (i=1;i<=n-1;i++)

         {       printf("*");

                  for (j=1;j<=n-i;j++)

                  printf (" ");

                  printf ("*\n");

         }

         printf("*\n");

         for (i=1;i<=n-1;i++)

         {       printf("*");

                  for (j=1;j<=i;j++)

                  printf (" ");

                  printf ("*\n");

         }      

}

1-24  V

#include<stdio.h>

intmain()

{       int n,i,j;

         scanf ("%d",&n);

         for (i=0;i<n;i++)

                  {       for (j=1;j<=2*(n-1)-i;j++)

                          {

                                   if (j==i+1)printf ("*");

                                   else printf(" ");

                          }

                          printf("*\n");

                  }

         return 0;

}

1-25  ^

#include<stdio.h>

intmain()

{       int n,i,j;

         scanf ("%d",&n);

         for(i=1;i<=n-1;i++)

         printf (" ");printf("*\n");

         for (i=1;i<n;i++)

                  {       for (j=1;j<=n-i-1;j++)

                          printf ("");printf ("*");

                          for(j=1;j<=2*i-1;j++)

                          printf ("");printf ("*\n");

                  }

         return 0;

}

1-26  N

#include<stdio.h>

intmain()

{       int n,i,j;

         scanf ("%d",&n);

         printf ("*");

         for(i=1;i<=n-2;i++)

         printf (" ");printf("*\n");

         for (i=1;i<=n-2;i++)

                  {       printf ("*");

                          for(j=1;j<=n-2;j++)

                          {       if (i==j) printf("*");

                                   elseprintf(" ");

                          }

                          printf("*\n");

                  }

         printf ("*");

         for(i=1;i<=n-2;i++)

         printf (" ");printf("*\n");

         return 0;

}

1-27   99乘法表正

#include<stdio.h>

intmain()

{       int n,i,j;

         for(i=1;i<=9;i++)

         printf ("%3d",i);

         printf ("\n");

         printf("----------------------------------\n");

         for (i=1;i<=9;i++)

         {       for(j=1;j<=9;j++)

                  {

                          if(j>=i)printf("%3d",i*j);

                          elseprintf("   ");

                  }

                  printf ("\n");

         }

         return 0;

}

1-28  99乘法表反

#include<stdio.h>

intmain()

{       int n,i,j;

         for(i=1;i<=9;i++)

         printf ("%3d",i);

         printf ("\n");

         printf("----------------------------------\n");

         for (i=1;i<=9;i++)

         {       for(j=1;j<=9;j++)

                  {

                          if(i+j>=10)printf("%3d",i*j);

                          elseprintf("   ");

                  }

                  printf("\n");

         }

         return 0;

}

1-29  数字菱形实心        4

             434

             43234

            4321234

             43234

             434

              4   

#include<stdio.h>//1的时候拿出来用if else重新写

 

intmain()

{       int i ,j ,n;

   printf("\nInput n=");

   scanf("%d",&n);

   for (j=1;j<=n-1;j++)

   printf (" ");printf("%d\n",n);

   for(i=1;i<=n-1;i++)

   {   for (j=1;j<=n-i-1;j++)

              printf(" ");

              for(j=n;j>=n-i;j--)

              printf("%d",j);

              for(j=n-i+1;j<=n;j++)

              printf ("%d",j);

              printf("\n");

   }

   for (i=1;i<n-1;i++)

   { for(j=1;j<=i;j++)

              printf(" ");

                  for (j=n;j>=i+1;j--)

                  printf ("%d",j);

                  for (j=i+2;j<=n;j++)

                  printf ("%d",j);

                  printf ("\n");

   }

   for (j=1;j<=n-1;j++)

   printf (" ");printf("%d\n",n);

}

1-30  数字菱形               1

               121

              12321

              1234321

              123454321

              1234321

              123321

               121

               1      

#include<stdio.h>//1的时候拿出来用if else重新写

intmain()

{       int i ,j ,n;

   printf("\nInput n=");

   scanf("%d",&n);

 

   for(i=n;i>=1;i--)

   {   for (j=1;j<=i-1;j++)

              printf(" ");

              for(j=1;j<=n+1-i;j++)

              printf("%d",j);

              for(j=n-i;j>=1;j--)

              printf("%d",j);

              printf("\n");

   }

   for (i=1;i<n;i++)

   { for(j=1;j<=i;j++)

              printf(" ");

                  for (j=1;j<=n-i;j++)

                  printf ("%d",j);

                  for (j=n-i-1;j>=1;j--)

                  printf ("%d",j);

                  printf ("\n");

   }

}

1-32数字菱形空心

                   A

                 B   B

               C       C

             D           D

           E               E

             D           D

               C       C

                  B   B

                    A  

#include <stdio.h>

int main()

{         int i ,j ,n;

  char abc,T;

  printf("\nInput char=");

   scanf("%c",&abc);

  printf("\nInput n=");

  scanf("%d",&n);

  for (i=1;i<=n;i++)

   {

              for (j=1;j<=n-2+i;j++)

              {      

                          T=abc+i-1;

                       while(T>'Z')T=T-26;while (T<'A')T=T+26;

                          if(i+j==n+1)printf ("%c",T);

                          elseprintf (" ");

                  }

              printf ("%C\n",T);                 

   }

  for (i=1;i<n;i++)

   {

              for (j=1;j<=n-2+n-i;j++)

              {      

                          T=abc+n-i-1;

                       while(T>'Z')T=T-26;while (T<'A')T=T+26;

                          if(j==i+1)printf ("%c",T);

                          elseprintf (" ");

                  }

              printf ("%C\n",T);                 

  } 

}

1-34               A

                  B C D

                E F G H I

              J K L M N O P

            Q R S T U V W X Y

#include<stdio.h>

int main()

{        int i ,j ,n;

   char abc,T;

   printf("\nInput char=");

   scanf("%c",&abc);

   printf("\nInput n=");

   scanf("%d",&n);

   for (i=1;i<=n;i++)

   { for(j=1;j<=n-i;j++)

              printf(" ");

              for(j=1;j<=2*i-1;j++)

              {       T=abc+i+j-2;

                       while(T>'Z')T=T-26;while (T<'A')T=T+26;

                          printf("%c",T);

              }

              printf("\n");                 

   }

}

1-35123454321                

     1234321

      12321

       121

            1

1-36  1-35的反

#include <stdio.h>

int main()

{   int i ,j,n;

  printf("\nInput n=");

  scanf("%d",&n);

 

  for(i=n;i>=1;i--)

   {    for (j=1;j<=i-1;j++)

        printf (" ");

        for (j=1;j<=n+1-i;j++)

        printf ("%d",j);

        for (j=n-i;j>=1;j--)

        printf ("%d",j);

        printf ("\n");

   }

}

     

二、应用          

2-1.编程,输出200以内所有完全平方数C(满足C2=A2+B2)及其个数。

intmain()

{    int a,b,c,n=0;

     for (c=1;c<=200;c++)//c在最外层 避免重复

     {  for(b=1;b<200;b++)

        { for (a=1;a<200;a++)

            if (c*c==a*a+b*b)

            {   printf("%d^2=%d^2+%d^2\n",c,a,b);

                n++;

                a=201;b=201;//跳出两个循环避免重复

            }

        }

     }

     printf ("0-200内完全平方数有%d个",n);

}

2-2.设N是一个四位数,它的9倍恰好是其反序数(例如:123的反序数是321),编程,输出所有满足条件的N。

intmain()

{    int n,fanxu(int),a;

     for (n=1000;n<=1111;n++)

     {  a=fanxu(n);

        if (a==9*n)

        printf ("%d %d\n",n,a);

     }

}

intfanxu(int x)

{    int f,s,t,four,num;

     f=x%1000%100%10;

     s=x/10%100%10;

     t=x/100%10;

     four=x/1000;

     num=f*1000+s*100+t*10+four;

     return num;  

}

2-3口袋中有12个球,其中3红,3白和6黑,从中任取8个球,编程,输出所有不同的取法。输出形式如下:

     RED   WHITE  BLACK

 ------------------------

  1:  0      2     6

  2:  0      3     5

int main()

{   inti,j,k,n=1;

    printf(" RED   WHITE  BLACK\n------------------------\n");

    for(i=0;i<=3;i++)

    {   for (j=0;j<=3;j++)

        for(k=0;k<=6;k++)

        if(i+j+k==8)

        {  

            printf("%4d:%4d%4d%4d\n",n,i,j,k);

            n++;

        }

    }  

}

2-4. 小明有五本新书,要借给A、B、C三位小朋友,每人每次只能借一本,编程,输出所有不同的借法

int main()

{                            int a,b,c;

                             printf ("人--书号  人--书号  人--书号\n");

                             for(a=1;a<=5;a++)

                             for(b=1;b<=5;b++)

                             for (c=1;c<=5;c++)

                             {    if (a!=b&&b!=c&&c!=a)

                                   printf("a--%d        b--%d        c--%d\n",a,b,c);

                             }

}

2-5.编程,求全部水仙花数。所谓水仙花数是指一个三位数,其各位数字立方的和等于该数。如:153 = 13 + 53+33

intmain()

{    int f,s,t,num,flag;

     for (num=100;num<=999;num++)

     { 

        f=num%10;

        s=num/10%10;

        t=num/100;

        flag=f*f*f+s*s*s+t*t*t;

        if (flag==num)

        printf("%d=%d^3+%d^3+%d^3\n",num,t,s,f);

     }

}

2-6.100匹马驮100担货,大马一匹驮3担,中马一匹驮2担,小马两匹驮1担。编程,输出所有满足条件的方案(即大、中、小马的数目)。

     int main()

{    int d,z,x;

     printf ("大   中   小\n");

     for (d=0;d<=100;d++)

     for (z=0;z<=100;z++)

     for (x=0;x<=100;x=x+2)//两匹马一旦 不能++ X只能是偶数

     { 

        if(d+z+x==100&&3*d+2*z+x/2==100)

        {

        printf("%4d%4d%4d\n",d,z,x);

        continue;

        }

     }

}

2-7.用一元人民币兑换成1分、2分和5分硬币,编程,输出所有不同的兑换方法及兑换方法个数。

 

 

 

三、链表

2017蓝桥杯C语言模拟赛试题和答案

  • 2017年11月27日 22:15
  • 32KB
  • 下载

2014蓝桥杯C语言本科B组初赛试题(个人答案)

2014年3月22号蓝桥杯C语言本科B组初赛试题(个人答案)
  • a120705230
  • a120705230
  • 2014-03-23 15:08:17
  • 6351

C语言试题C语言试题100个

  • 2010年06月10日 12:39
  • 3.52MB
  • 下载

C语言 程序设计竞赛试题!

学校要举办程序设计竞赛了,我报名参加了,用的是C语言,说题目是  生活中的实际问题。请问下谁有关于程序设计竞赛的资料或者给提个建议,比如说要复习哪一方面的内容(数据结构或其他的),都可以啊,谢谢了啊。...
  • lqg5209
  • lqg5209
  • 2007-04-10 19:05:00
  • 1119

2015年4月第六届蓝桥杯c/c++B组省赛试题和个人解答

又一年的蓝桥杯,好久没那么爽快的做题了,昨天上午刚考完蓝桥杯,我把题带出来了。不废话,上题。      一、 奖券数目 有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。 虽...
  • Dodd9199
  • Dodd9199
  • 2015-04-12 11:35:00
  • 6303

C语言考研试题和历年考试题

  • 2009年05月07日 00:41
  • 382KB
  • 下载

2013蓝桥杯C语言编程题库和答案 -

  • 2013年11月23日 14:19
  • 124KB
  • 下载

2017年蓝桥杯省赛C语言B组真题

  • 2017年04月08日 16:04
  • 36KB
  • 下载

2014届蓝桥杯 本科B组C语言试题

  • 2014年03月23日 17:44
  • 32KB
  • 下载

2014蓝桥杯C语言本科B组初赛试题

  • 2015年01月27日 10:15
  • 30KB
  • 下载
收藏助手
不良信息举报
您举报文章:C语言试题记录
举报原因:
原因补充:

(最多只允许输入30个字)