Posts

Showing posts from July, 2021

12.c++ program to print numbers from 1 to 10 using for loop

Image
//C++ program to print numbers from 1 to 10 INPUT: #include<iostream> using namespace std; int main() {     int i;     for(i=1;i<=10;i++)         {             cout<<i<<endl;         }     return 0; } OUTPUT:  

10.c++ program to check if a leap year or not

Image
// C++ program to check if a year is leap year or not INPUT: #include<iostream> using namespace std; int main() {     int z;     cout<<"Enter a year:";     cin>>z;     if(z%4==0){         if(z%100==0){             if(z%400==0)                 cout<<"\n\t"<<z<<" is a leap year";             else                 cout<<"\n\t"<<z<<" is not a leap year";         }         else             cout<<"\n\t"<<z<<" is a leap year";     }     else         cout<<"\n\t"<<z<<" is not a leap year";     return 0; } OUTPUT:

9.c++ program to print number entered by user

Image
  // C++ program to print number entered by user INPUT: #include<iostream> using namespace std; int main() {     int a;     cout<<"Enter an integer : ";     cin>>a;     cout<<"\n"<<" You Entered "<<a<<endl;     return 0; } OUTPUT:

8.c++ program to check whether the number is even or odd

Image
FIRST METHOD:   // C++ program to check whether the number is even or odd using if else INPUT: #include<iostream> using namespace std; int main() {     int z;     cout<<"\n Enter an integer:";     cin>>z;     if(z%2==0)         cout<<"\n\t"<<z<<" is Even "<<endl;     else         cout<<"\n\t"<<z<<" is Odd "<<endl;     return 0; } SECOND METHOD: // C++ program to check whether the number is even or odd using ternary operators INPUT: #include<iostream> using namespace std; int main() {     int z;     cout<<"Enter an integer : ";     cin>>z;     (z%2==0) ? cout<<"\n\t"<<z<<" is Even "<<endl : cout<<"\n\t"<<z<<" is Odd "<<endl;     return 0; } OUTPUT:

7.c++ program to swap two numbers using 6 methods

Image
SWAPPING NUMBERS USING 6 METHODS: FIRST METHOD: // C++ program to swap numbers using temporary variable INPUT: #include<iostream> using namespace std; int main() {     int x,y,z;     cout<<"Enter The Value of x : ";     cin>>x;     cout<<"Enter The Value of y : ";     cin>>y;     cout<<"\n\t Before Swapping"<<endl;     cout<<"x = "<<x<<endl;     cout<<"y = "<<y<<endl;     z=x;     x=y;     y=z;     cout<<"\n\t After Swapping"<<endl;     cout<<"x = "<<x<<endl;     cout<<"y = "<<y<<endl;     return 0; } SECOND METHOD: // C++ program to swap numbers without using Temporary variables using addition and subtraction operator INPUT: #include<iostream> using namespace std; int main() {     int x,y;     cout<<"Enter The Value of x : ";     cin>>x;     cout<<&

6.c++ program to get an ASCII value and display the corresponding character

Image
 // C++ program to get an ASCII value and display the corresponding character #include<iostream> using namespace std; int main() {     int a;     char b;     cout<<"\n Enter ASCII code (0 to 255):";     cin>>a;     b=a;     cout<<"\n Equivalent Character:"<<b<<endl; } OUTPUT:

4.c++ program to compute quotient and remainder

Image
  // C++ program to compute quotient and remainder INPUT: #include<iostream> using namespace std; int main() {     int divisor,dividend,quotient,remainder;     cout<<"Enter Dividend:";     cin>>dividend;     cout<<"Enter Divisor:";     cin>>divisor;     quotient=dividend/divisor;     remainder=dividend%divisor;     cout<<"\n Quotient = "<<quotient<<endl;     cout<<"\n Remainder = "<<remainder<<"\n";     return 0; } OUTPUT:

3.c++ Program to accept any character and display its next character

Image
 // C++ Program to accept any character and display its next character INPUT: #include<iostream> using namespace std; int main() {     char a;     cout<<"\n Enter a character:";     cin>>a;     a=a+1; cout<<"\n The Next character:"<<a<<"\n"; } OUTPUT:

5.c++ program to get 2 integer numbers and display their sum

Image
  Introduction to fundamental Data types:          Fundamental data types are predefined data types available with C++.There are five fundamental data types in  C++:                                 - char                                        - int                                        - float                                        - double                                        - void.                  Actually, these are the keywords for defining the data types. (1) int data type:          Integers are whole numbers without any fraction. Integers can be positive or negative. Integer data types accepts and returns only integer numbers. if a variable is declared as an int, C++ compiler allows storing only integer values into it. if you try to store a fractional value in an int type variable it will accept only the integer portion of the fractional value..      // C++ program to get 2 integer numbers and display their sum INPUT: #include<iostream> using namespace std; int main(

2.c++ program to find the area of a circle

Image
// C++ program to find the area of a circle INPUT: #include<iostream> using namespace std; int main() {     int radius;     float area;     cout<<"\n Enter Radius:";     cin>>radius;     area = 3.14 * radius * radius;     cout<<"\n The area of circle = "<<area; } OUTPUT:

C++ Program to print a string

Image
  //C++ program to print a string INPUT: #include<iostream> using namespace std; int main() {        cout<< "Subscribe our channel";        return 0; } OUTPUT:

1.c++ program to find the total marks and average of three subjects

Image
 //  C++ program to find the total marks and average of three subjects  INPUT: #include<iostream>  using namespace std;  int main()  {          int a,b,c,sum,avg;          cout<<"\n Enter Mark 1:";         cin>>a;          cout<<"\n Enter Mark 2:";          cin>>b;          cout<<"\n Enter Mark 3:";         cin>>c; sum = a + b + c;         avg = sum / 3;          cout<<"\n The sum = "<<sum;         cout<<"\n The average = "<<avg<<"%"; } OUTPUT: