Write a C program to generate and display a table of n and n2 for integer values of n ranging from 1 through 10?

1 answer

Answer

1116111

2026-07-22 02:36

+ Follow

#include

void main ()

{


int i = 0; // This is initialising variables.

int n = 0;

int n2 = 0;


printf("n\t\tn^2\t\t\n______________________________\n"); // This creates the top line of the table, the "____" creates a line, the \t tabs across to create the headers making the heading look neater and more presentable.


for (i=0; i<=10; i=(i+1)) //setting conditions for loop

{


n2 = (i*i); // This is creating the second variable n2.


printf("%d\t\t%d\t\t\n", i, n2); // assigning variables n and n2 to rows.

}


system("pause"); // Pausing the program so I can view it in the execution window.

}



That should be it but correct me if im wrong.

ReportLike(0)ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.