Write a program to print the square value of numbers from 1 to 10
Answers
Answer:
How do I write a program that displays numbers 1 to 10 and their squares?
This seems like a school assignment. So, I’d like to help you to understand computer programming technique so that you can write programs yourself next time.
Forget computer programming for a while, take a pen and a pencil or open some text processor like Wordpad or LibreOffice Writer or whatever you have installed on your computer.
Explanation:
I HOPE IT HELP YOU PLEASE FOLLOW ME
I’ll write this program in C++.
#include <iostream>
int main(){
std::cout<<"1 2 3 4 5 6 7 8 9 10\n1 4 9 16 25 36 49 64 81 100\n";
}
If you are not familiar with C++, ‘std::cout<<’ is a way of outputting and ‘\n’ is to skip to the next line. All of the work done is in the main() function. Don’t care about “#include <iostream>” It’s not that important.
for(execute before for loop ; when to execute for loop ; what to do after each loop){
}
For example,
for(i=0;i<10;i++){
std::cout<<"a";
}
First, I set i to 0, and I repeat outputting “a” when i<10, and I increase i by 1 every time I output. So the output should be ”aaaaaaaaaa”;
If we want to output 1 through 10 along with their squares, we can write:
#include <iostream>
int main(){
int i;
for(i=1;i<=10;i++){
std::cout<<i<<" "<<i*i<<" ";
}
cout<<"\n";
}
C:
#include <stdlib.h>
#include <stdio.h>
main(){
int i;
for(i=1;i<=10;i++){
print("%d %d ",i,i*i);
}
puts("");
}
Java:
public class a{
public static void main(){
int i;
for(i=1;i<=10;i++){
System.out.printf("%d %d ",i,i*i);
}
System.out.println("");
}
}