Followers

Monday, April 10, 2023

Program That Take A Number And Prints Its Table Upto 10

Program:
 #include <iostream>  
 using namespace std;  
 int main() {    
   int num;  
   cout<<"Enter the number to print table: ";  
   cin>>num;  
   cout<<"Table Of "<<num<<endl;  
   for(int i=1; i<=10; i++){  
        cout<<num<<" x "<<i<<" = "<<num * i<<endl;  
      }  
   return 0;  
 }  
Output: 


















Working Of The Program:
1.The #include <iostream> directive includes the input/output stream library that allows us to 2. read input and write output to the console.
3. The using namespace std statement indicates that we want to use the standard namespace, which contains standard C++ library functions and objects.
4. The int num declares an integer variable num that will store the number whose table we want to print.
5. The cout<<"Enter the number to print table: "; statement displays the message "Enter the number to print table: " to the console.
6. The cin>>num; the statement reads an integer input from the user and stores it in the variable num.
7. The cout<<"Table Of "<<num<<endl; statement displays the message "Table Of (num)" to the console, where (num) is the value of the num variable.
8. The for(int i=1; i<=10; i++) loop runs 10 times and initializes a loop counter i to 1, increments it by 1 each time, and checks whether it is less than or equal to 10.
9. The cout<<num<<" x "<<i<<" = "<<num * i<<endl; statement displays the product of num and i in the format "num x i = product" to the console for each iteration of the loop.
10. The return 0; statement exits the program and returns a value of 0 to the operating system, indicating that the program executed successfully.










No comments:

Post a Comment

Program to Find the Length of a String

Program: #include <iostream> using namespace std; int main() { string a; cout<<"Enter the string...