C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.
Wap to print table from 1 to 9 using for loop in c++ language. Coding:- #include<iostream.h> #include<conio.h> void main() { clrscr(); int i,j,k; for(i=1;i<=9;i++) { for(j=1;j<=10;j++) { k=i*j; cout<<k<<" "; } cout<<"\n"; }getch(); } Output:-
//WAP to calculate the factorial of a given number in c++ language. #include<iostream.h> #include<conio.h> void main() { clrscr(); int i,fact=1,n; cout<<"enter number to find its factorial"<<" "; cin>>n; for(i=2;i<=n;i++) { fact=fact*i; } cout<<"factorial of nos is"<<fact; getch(); } output:-
//wap to print even nos up to 100 using for loop in c++ language. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a; cout<<"Even nos are:"<<endl; for(a=1;a<=100;a++) { if(a%2==0) { cout<<a<<" "; } } getch(); } Output:-
//WAP to calculate sum of n nos using for loops in c++ language.
#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,n,sum=0; cout<<"enter the value of n:"<<endl; cin>>n; for(i=1;i<=n;i++) { sum=sum+i; } cout<<"the sum of n nos is:"<<sum; getch(); } Output:-
//wap to print even nos upto 100 using for loop in c++ language. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a; cout<<"Numbers 1 to 10 are :"<<"\n"; for(a=1;a<=10;a++) { cout<<"\n"<<a; } getch(); }
//WAP to find out number of days in a month using switch case.
#include<iostream.h> #include<conio.h> void main() { clrscr(); int m,y; cout<<"enter month no."<<endl; cin>>m; cout<<"enter year"<<endl; cin>>y; switch(m) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: cout<<"No of days in this month is 31"<<endl; break; case 4: case 6: case 9: case 11: cout<<"No of days in this month is 30"<<endl; break; case 2: if(y%4==0) { cout<<"it is a leap year"<<endl; cout<<"so no of days is 29"<<endl; } else cout<<"no of days in a month is 28"<<endl; break; default: cout<<"error"<<endl; break; } getch(); }
//WAP to print different calculations using switch case. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,d; char ch; cout<<"enter the values of a and b"; cin>>a>>b; cout<<"enter the operator or case"; cin>>ch; switch(ch) { case '+': d=a+b; cout<<"sum of a and b is:"<<" "<<d<<endl; break; case '*': d=a*b; cout<<"multiplication of a and b is:"<<" "<<d<<endl; break; case '-': d=a-b; cout<<"subtraction of a and b is:"<<" "<<d<<endl; break; case '/': d=a/b; cout<<"division of a and bis:"<<" "<<d<<endl; break; default: cout<<"wrong case no calculations:"<<endl; break; } getch(); }
//WAP to print the days of weeks by using switch case. #include<iostream.h> #include<conio.h> void main() { clrscr(); int c; cout<<"enter any case"; cin>>c; switch(c) { case 1: cout<<"monday"<<endl; break; case 2: cout<<"tuesday"<<endl; break; case 3: cout<<"wednesday"<<endl; break; case 4: cout<<"thrusday"<<endl; break; case 5: cout<<"friday"<<endl; break; case 6: cout<<"saturday"<<endl; break; default: cout<<"error"<<endl; break; } getch(); } Output:-
//WAP to calculate division obtain by students using else if condition statement. #include<iostream.h> #include<conio.h> void main() { clrscr(); int m1,m2,m3,per; cout<<"enter the marks of enlish"; cin>>m1; cout<<"enter the marks of maths"; cin>>m2; cout<<"enter the manrks of science"; cin>>m3; per=(m1+m2+m3)/3; if(m1>=40 && m2>=40 && m3>=40) { if(per>=60) { cout<<"first division"<<per<<" "<<per<<"%"; } else if(per>=50) { cout<<"second division"<<" "<<per<<"%"; } else if(per>=40) { cout<<"third division"<<" "<<per<<"%"; } } else { cout<<"you are fail in one or more subjects"; } getch(); }
//Write a program to Check Whether Number is Even or Odd.
#include <iostream.h> #include<conio.h>
int main() { clrscr(); int num; cout << "Enter an integer: "; cin >> num; if ( num%2 == 0) { cout << num << " is even."; } else { cout << num << " is odd.";
//Write A Program to ADD , MULTIPLY , SUBTRACT and DIVIDE two no's.
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,add,sub,mul,div; cout<<"Enter first no or value of a="; cin>>a; cout<<"Enter second no or value of b="; cin>>b; add=a+b; sub=a-b; mul=a*b; div=a/b; cout<<"Sum of a & b ="<<add<<endl; cout<<"Subtraction of a & b ="<<sub<<endl; cout<<"Multiplication of a & b ="<<mul<<endl; cout<<"Division of a & b ="<<div<<endl; getch(); }