Back to Editorials CodeCraft
  • Github
  • Instagram
< >

Square and Cubic

TIME LIMIT = 5 SECS.
  • Write a program that reads an integer N (1 < N < 1000). This N is the number of output lines printed by this program.
Input Output
The input file contains an integer N Print the output according to the given example.
Example Test Case
Input              Output
5 1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
Solution

#include <stdio.h> int main() { int n, i; /* 'N' is the number up to which the squares and cubes are to be printed. 'i' is the looping variable. */ scanf("%d", & n); //Accept 'n' for (i = 1; i <= n; i++) { //Loop and print the squares and cubes of every number up to N separated by a new line. printf("%d %d %d\n", i, i * i, i * i * i); } return 0; }
  • #1 Squared and cubic
  • #2 Digits
  • #3 Multiple Adder
  • #4 Grains in a Chessboard
  • #5 Age In Days
  • #6 Stay or Go
  • #7 Cipher

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();