Posts

Showing posts from May, 2022

Write a program that asks the user for a number n and prints the sum of the numbers 1 to n.

Input :   100 Output :   The sum of numbers from 1 to 100 is : 5050 Program: #include<iostream> using namespace std; //Write a program that asks the user for a number n and prints the sum of the numbers 1 to n. int main() {     int n,sum;     cout<<"Enter the number : ";     cin>>n;     sum=(n)*(n+1)/2;     cout<<"The sum of numbers from 1 to "<<n<<" is : "<<sum;     return 0; }

When only Some specific user name will be greeted in a C++ Program.

Modification of previous program. Program: #include<iostream> #include<string> //here string file is used to use string reserved keyword using namespace std; int main() {     string Name, response;     cout<<"Please give Your name : ";     getline(cin, Name); //getline is used to store character entered after space button is clicked     if((Name=="Alice")||(Name=="Bob"))  //Here || is logical OR operator.     {         cout<<"Namaste, "<<Name;     }     else     {         cout<<"You are out of the program";     }     return 0; } Note : If you want to see the previous program then click here PROGRAM

A program that asks the user for their name and greets them with their name.

If you want to display Full Name in C++ than you are on a right place. Example: #include<iostream> #include<string> using namespace std; int main() {     string name;     cout<<"Please give Your name : ";     getline(cin, name);     cout<<"Namaste, "<<name;     return 0; } Output: Please give Your name : Rudra Pratap Singh Namaste, Rudra Pratap Singh

Hello World Program in C++

Image
A simple Program That displays Hello World on the screen  By using C++ Programming language.          Code:                  Output: