Practice Program







  • Program of printing 'n' odd numbers
  • Solution : through for loop
    void main()
    {
        int n,i;
        printf("Which number table you want: ");
        scanf("%d",&n);
    
        printf("\nTable of %d is :\n",n);
        for(i=1;i<=10;i++)
        {
            printf("\n%d X %d  = %d",n,i,n*i);
    
        }
    
    }
    

    Output1
    Which number table you want:5
    5 X 1 = 5
    5 X 2 = 10
    5 X 3 = 15
    5 X 4 = 20
    5 X 5 = 25
    5 X 6 = 30
    5 X 7 = 35
    5 X 8 = 40
    5 X 9 = 45
    5 X 10 = 50
    Output2
    Which number table you want:7
    7 X 1 = 7
    7 X 2 = 14
    7 X 3 = 21
    7 X 4 = 28
    7 X 5 = 35
    7 X 6 = 42
    7 X 7 = 49
    7 X 8 = 56
    7 X 9 = 63
    7 X 10 = 70
    Output3
    Which number table you want:9
    9 X 1 = 9
    9 X 2 = 18
    9 X 3 = 27
    9 X 4 = 36
    9 X 5 = 45
    9 X 6 = 54
    9 X 7 = 63
    9 X 8 = 72
    9 X 9 = 81
    9 X 10 = 90





    Solution : through while loop
    void main()
    {
        int n,i;
        printf("Which number table you want to display: ");
        scanf("%d",&n);
       i=1;
        printf("\nTable of %d is :\n",n);
        while(i<=10)
        {
            printf("\n%d X %d  = %d",n,i,n*i);
            i++;
        }
    
    }
    






    Solution: ,from do-while loop
    void main()
    {
        int n,i;
        printf("Which number table you want to display: ");
        scanf("%d",&ampn);
       i=1;
        printf("\nTable of %d is :\n",n);
        do
        {
            printf("\n%d X %d  = %d",n,i,n*i);
            i++;
        }while(i<=10);
    
    }