3. Write a program to print the square and cube of a number.
Answers
Answer:
and Expressions: Exercise-42 with Solution
Write a C program to print a number, it’s square and cube in a line, starting from 1 and print n lines. Accept number of lines (n, integer) from the user.
Pictorial Presentation:
C Programming: Print 3 numbers in a line, starting from 1 and print n lines
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int a, i, j = 1, x = 0;
printf("Input number of lines: ");
scanf("%d", &a);
for(i = 1; i <= a; i++) {
printf("%d %d %d\n", i, i*i, i*i*i);
}
return 0;
}
Copy
Sample Output:
Input number of lines: 5
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
Flowchart:
C Programming Flowchart: Print 3 numbers in a line, starting from 1 and print n lines
C programming Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C program to print 3 numbers in a line, starting from 1 and print n lines. Accept number of lines (n, integer) from the user.
Next: Write a C program that reads two integers p and q, print p number of lines in a sequence of 1 to b in a line.
What is the difficulty level of this exercise?
EASY MEDIUM HARD
Based on 27 votes, average difficulty level of this exercise is Easy .
New Content published on w3resource :
Python Numpy exercises
Python GeoPy Package exercises
Python Pandas exercises
Python nltk exercises
Python BeautifulSoup exercises
Form Template
Composer - PHP Package Manager
PHPUnit - PHP Testing
Laravel - PHP Framework
Angular - JavaScript Framework
React - JavaScript Library
Vue - JavaScript Framework
Jest - JavaScript Testing Framework
by TaboolaSponsored LinksYou May Like
Give strength to your financial security planning with this
Max Life Insurance Quotes
FREE AI, VR, App Dev Class For Your Kid. Age 7-15 Years
CampK12
Protect Yourself and your Family and Friends From mosquitoes, rats, lizards, rats, flies, cockroaches.
Pest Safe Device
Cheap SUVs in India Might Surprise You
SUV Prices | Search Ad
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
©w3resource.com 2011-2020
PrivacyAboutContactFeedbackAdvertise
please mark me as billaint