Latest web development tutorials

C Exercise Example 88

100 cases of classic C language 100 cases of classic C language

Title: 7 reads the number (1-50) integer values, each read a value, the program prints out the number of the value *.

Program Analysis: None.

Source Code:

//  Created by www.w3big.com on 15/11/9.
//  Copyright © 2015年 本教程. All rights reserved.
//

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,i,j;
    printf("请输入数字:\n");i--;
    for(i=0;i<7;i++)
    {
        scanf("%d",&n);
        if(n>50){
            printf("请重新输入:\n");i--;
        }
        else
        {
            for(j=0;j<n;j++)
                printf("*");
        }
        printf("\n");
    }
    return 0;
}

Run the above example output is:

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

100 cases of classic C language 100 cases of classic C language