by CodeChum Admin
We've already tried printing out the values of an array in reversed order, right? Today, we shall compute for the squares of all the numbers.
There's already a predefined array/list containing 100 integer values. Loop through each values, compute their squares, and display them.
Output
Multiple lines containing an integer.
4
9
25
10000
49
9
25
9
1
16
.
.
.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 100
int main(void)
{
int a[SIZE] = {0};
srand(time(NULL));
printf("\tNumber\tSquare\n");
for(int i = 1; i <= SIZE; ++i)
{
a[i] = 1 + rand() % 100;
printf("%d\t%d\t%d\n", i, a[i], a[i] * a[i]);
}
}
Comments
Leave a comment