Wap to print following pattern using for loop in c++ language.
// *
// * *
// * * *
// * * * *
Coding:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"enter the no of rows:";
cin>>n;
for(i=1; i<=n; i++)
{
for( j=n-i;j>=1; j--)
{
cout<<" ";
}
for(k=1; k<=i; k++)
{
cout<<"* ";
}
cout<<"\n";
}
getch();
}
Output:-
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 print following pattern using for loop in C++ Language.
// 1
// 2 3
// 4 5 6
// 7 8 9 10
// 11 12 13 14
Coding:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
cout<<n;
n++;
}
cout<<"\n";
}getch();
}
Output:-
//Wap to print following pattern using for loop in c++ language.
// 1
// 2 2
// 3 3 3
// 4 4 4 4
// 5 5 5 5 5
Coding:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n;
cout<<"Enter the value of n";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
cout<<i;
}
cout<<"\n";
}getch();
}
Output:-
// Wap to print following pattern using for loop in c++ language.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Coding:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n;
cout<<"Enter the value of n";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
cout<<j;
}
cout<<"\n";
}getch();
}
Output:-
//wap to form table of 2 using for loop in c++ language.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=2,b=1,c,n;
cout<<"Table of 2 is :-"<<endl;
for(n=1;n<=10;n++)
{
c=a*b;
cout<<a<<"*"<<b<<"="<<c<<"\n";
b=b+1;
}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();
}
Output:-
//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();
}
Output:-
//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();
}
Output:-
//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();
}
Output:-
//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.";
}
getch();
return 0;
}
Output:-
// Write a program to perform Celsius to Fahrenheit conversion.
#include<iostream>
#include<conio.h>
int main()
{
clrscr();
float fahrenheit, celsius;
cout << "Enter the temperature in Celsius : ";
cin >> celsius;
fahrenheit = (celsius * 9.0) / 5.0 + 32;
cout<<"The temperature in Celsius : " << celsius << endl;
cout<<"The temperature in Fahrenheit:" << fahrenheit << endl;
getch();
return 0;
}
Output:-
// Write a program to find simple interest.
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int p,t;
float r,si;
cout<<"Enter Principle : ";
cin>>p;
cout<<"Enter Rate : ";
cin>>r;
cout<<"Enter Time : ";
cin>>t;
si=(p*r*t)/100;
cout<<"Simple interest is : "<<si;
getch();
return (0);
}
OutPut:-
//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();
}
OutPut:-