Classic C Program (19/20)

Publisher:数字梦行Latest update time:2015-02-04 Source: laogu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Title: Print stairs and print two smiling faces above the stairs.
1. Program analysis: Use i to control rows, j to control columns, and j controls the number of black squares output according to the change of i.
2. Program source code:
#include "stdio.h"
main()
{
int i,j;
printf("\1\1\n");/*Output two smiling faces*/
for(i=1;i<11;i++)
 {
 for(j=1;j<=i;j++)
   printf("%c%c",219,219);
 printf("\n");
 }
}

 

Title: Output a chess board.
1. Program analysis: Use i to control rows, j to control columns, and output black or white squares based on the sum of i+j.
2. Program source code:
#include "stdio.h"
main()
{
int i,j;
for(i=0;i<8;i++)
 {
  for(j=0;j<8;j++)
   if((i+j)%2==0)
    printf("%c%c",219,219);
   else
    printf(" ");
   printf("\n");
 }
}

 

Title: Output 9*9 formula.
1. Program analysis: Consider rows and columns, a total of 9 rows and 9 columns, i controls rows, j controls columns.
2. Program source code:
#include "stdio.h"
main()
{
 int i,j,result;
 printf("\n");
 for (i=1;i<10;i++)
  { for(j=1;j<10;j++)
    {
     result=i*j;
     printf("%d*%d=%-3d",i,j,result);/*-3d means left alignment, occupies 3 digits*/
    }
   printf("\n");/*New line after each line*/
  }
}

Title: Output special patterns. Please run it in C environment and take a look. Very Beautiful!
1. Program analysis: There are 256 characters in total. Different characters have different patterns.      
2. Program source code:
#include "stdio.h"
main()
{
char a=176,b=219;
printf("%c%c%c%c%c%c\n",b,a,a,a,b);
printf("%c%c%c%c%c%c\n",a,b,a,b,a); printf("%c%c%c%c%c%c\n",a,a,b,a,a);
printf("%c%c%c%c%c%
c\n",a,b,a,b,a); printf("%c%c%c%c%c%c\n",a,b,a,b,a);
printf("%c%c%c%c%c%c\n",b,a,a,a,b);}

 

Title: Use the * symbol to output the pattern of the letter C.
1. Program analysis: You can first use the * symbol to write the letter C on paper, and then output it in separate lines.
2. Program source code:
#include "stdio.h"
main()
{
printf("Hello C-world!\n");
printf(" ****\n");
printf(" *\n");
printf(" * \n");
printf(" ****\n");
}
Reference address:Classic C Program (19/20)

Previous article:Classic C Program (20/20)
Next article:Classic C Program (18/20)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号