Showing posts with label loop. Show all posts
Showing posts with label loop. Show all posts

Saturday, 12 December 2015

write a program that input a number and display its table

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int n,c;
c=1;
cout<<"Enter a number to get table"<<endl;
cin>>n;
while(c<=10)
{cout<<n<<"*"<<c<<" = "<<n*c<<endl;
c++;
} getch();
}

WRITE a program that show all the possible combination of 123 with nested loop in c++

#include<iostream>
#include<conio.h>
using namespace std;
main ()
{ int i=1,j=1,k=1,l=1;
for(i=1;i<=3;i++)
{for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)

 cout<<"\t"<<i<<j<<k; }
}
getch();}

write a program that show A-Z alphabets with loop structure in c++

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ char a;
a='A';
do{ cout<<a<<" "; a++;
} while(a<='Z');
getch();
}

Write a progtam that inputs marks from 0-100 and tells the grade of student with if statement in c++

#include<iostream>
using namespace std;
main()
{ int marks;
cout<<"Enter Marks to know grades"<<endl;
cin>>marks;
if(marks>=80)
cout<<"You have passed with A grade"<<endl;
else if(marks>=70)
cout<<"You have passed with B grade"<<endl;
else if(marks>=60)
cout<<"You have passed with C grade"<<endl;
else if(marks>=50)
cout<<"You have passed with D grade"<<endl;
else if(marks>=40)
cout<<"You have passed with E grade"<<endl;
else
cout<<"You have failed"<<endl;
system("pause");
}

Friday, 11 December 2015

write a program that give the following shape using loop in c++

*****
****
**
*


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int a,b;
for(a=5;a>=1;a--)
 { for(b=1;b<=a;b++)
 cout<<"*";
 cout<<endl;
 }
 getch();}

write a program which multiply numbers from 1 - 10 using loop in c++

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int n,sum;

sum=1;
n=1;
while(n<=10)
{ sum=sum*n;
n++;
} cout<<"product is = "<<sum;
getch();}

enter a number and reverse its digits using loop c++

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ long int n,num,digit,rev=0;
cout<<"Enter a number to reverse its digits "<<endl;
cin>>num;
n=num;
do
{ digit=num%10;
rev=(rev*10)+digit;
num=num/10;
}while(num!=0);
cout<<"reverse is "<<rev<<endl;
getch();
}

program to Make diamond using loop in c++

#include<iostream>
#include <conio.h>
using namespace std;
int main()
{
  int n=4,c,k,space=1;  
   space=n-1;
  for(k=1;k<=n;k++)
  {
    for(c=1;c<=space;c++)
      cout<<" ";
     space--;
     for(c=1;c<=2*k-1;c++)
      cout<<"*";
     cout<<endl;
  }
  space=1;
   for(k=1;k<=n-1;k++)
  {
    for(c=1;c<=space;c++)
      cout<<" ";
     space++;
     for(c=1;c<=2*(n-k)-1;c++)
      cout<<"*";
     cout<<endl;
  }
   getch();
}

Make A heart using loops in c++

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
 cout<<"\n\n\n\n\n\n\n";

 for(int i=0;i<15;i++)
 cout<<" ";
 cout<<"*         *";
 cout<<endl;

 for(int j=0;j<13;j++)
 cout<<" ";
 cout<<"*   *     *   *";
 cout<<endl;

 for(int k=0;k<11;k++)
 cout<<" ";
 cout<<"*      *   *      *";
 cout<<endl;

 for(int l=0;l<11;l++)
 cout<<" ";
 cout<<"*       * *       *";
 cout<<endl;

 for(int m=0;m<11;m++)
 cout<<" ";
 cout<<"*        *        *";
 cout<<endl;

 for(int n=0;n<11;n++)
 cout<<" ";
 cout<<"*                 *";
 cout<<endl;

 for(int o=0;o<12;o++)
 cout<<" ";
 cout<<"*               *";
 cout<<endl;

 for(int p=0;p<13;p++)
 cout<<" ";
 cout<<"*             *";
 cout<<endl;

 for(int q=0;q<14;q++)
 cout<<" ";
 cout<<"*           *";
 cout<<endl;

 for(int r=0;r<15;r++)
 cout<<" ";
 cout<<"*         *";
 cout<<endl;

 for(int s=0;s<17;s++)
 cout<<" ";
 cout<<"*     *";
 cout<<endl;

 for(int t=0;t<20;t++)
 cout<<" ";
 cout<<"**";
 cout<<endl;
 getch();}