Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How Would I go about Printing a Statement after each iteration of the loop? C

Im very new to C, The programs primary function is to print multiplication tables up to the users specified integers. But the main thing that Im missing is being able to print the designated times table for which is being printed. For example this is the 1’s time table this is the 2’s time table etc. Thanks for your Help.

This is my output…

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is the Output i’am Looking to get to….

enter image description here

RAW CODE:

#include<stdio.h>


int main()
{
     int i, j, n, z,  product;
    
    printf("Please Enter an Interger: ");
    scanf("%d", &n);
    
    //next Interger
    
    printf("Please Enter an Interger: ");
    scanf("%d", &z);
    
     /* Generating Multiplication Table */
     for(i=1;i<=n;i++)
     {
          for(j=1;j<=z;j++) //Nested For Loop to iterate until the second interger is met
          {
               product = i*j;
               printf("%d x %d = %d\t", i, j, product);
          }
          printf("\n");
     }
     return(0);
}

>Solution :

You are looking for this.

#include <stdio.h>

int main()
{
    int n, m, i, j, product;
    
    printf("Enter integer: ");
    scanf("%d", &n);
    
    printf("Enter integer: ");
    scanf("%d", &m);
    
    printf("\n");
    
    for(i=1; i<=n; i++) {
        printf("* %d Times Table*\n", i);
        for(j=1;j<=m; j++) {
            product = i*j;
            printf("\t%d x %d = %d\n", i, j, product);
        }
        printf("****************");
        printf("\n\n");
    }
    

    return 0;
}

The logic was fine, but you had to fix a bit your printf usage.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading