C Exercise Example 88

100 Classic C Examples

Title:Read the integer values of 7 numbers (1-50). Each time a value is read, the program prints * equal to that value count.

Program analysis:None.

Example

// Created by www.example.com on 15/11/9. // Copyright © 2015 Example. All rights reserved. // #include<stdio.h> #include<stdlib.h> int main() { int n,i,j; printf("Please enter a number:\n");i--; for(i=0;i<7;i++) { scanf("%d",&n); if(n>50){ printf("Please re-enter:\n");i--; } else { for(j=0;j<n;j++) printf("*"); } printf("\n"); } return 0; }

The output of running the above example is:

请输入数字:
5
*****

100 Classic C Examples

other extensions