0% found this document useful (0 votes)
53 views7 pages

Assignment - 1: 1.write A C++ Program To Generate Multiplication Table. Code

The document contains 5 C++ programs: 1) A program to generate a multiplication table. 2) A program to check if a number is a palindrome. 3) A program to print a half pyramid of alphabets. 4) A program to find the lowest common multiple of two numbers. 5) A program to find the roots of a quadratic equation. Each program includes the code, inputs/outputs and description of the program.

Uploaded by

honey yorac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views7 pages

Assignment - 1: 1.write A C++ Program To Generate Multiplication Table. Code

The document contains 5 C++ programs: 1) A program to generate a multiplication table. 2) A program to check if a number is a palindrome. 3) A program to print a half pyramid of alphabets. 4) A program to find the lowest common multiple of two numbers. 5) A program to find the roots of a quadratic equation. Each program includes the code, inputs/outputs and description of the program.

Uploaded by

honey yorac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment – 1

1.write a c++ program to generate multiplication table.


Code:
#include <iostream>
using namespace std;
int main()
{
int a,n,i,b,c;
cout<<"Enter NO of for table :";
cin>>n;
for(i=1;i<=10;i++)
{
b=n*i;
cout<<b<<endl;
}
return 0;
}

Output:
2. Write a c++ program to check Palindrome number.
Code:
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d=0;
cout<<"Enter Number :"<<endl;
cin>>a;
b=a;
while(a>0)
{
c=a%10;
d=d*10+c;
a=a/10;

}
if(b==d)
{
cout<<b<<" is Palindrome."<<endl;
}
else
{
cout<<b<<" is not Palindrome."<<endl;
}
return 0;
}

Output:
3. program to print half pyramid using alphabets.
A
BB
CCC
DDDD
EEEEEE
Code:
#include <iostream>
using namespace std;
int main()
{
int a,i,j;
char ch='A';
cout<<"Enter Number :";
cin>>a;
for(i=1;i<=a;i++)
{
for(j=0;j<i;j++)
{
cout<<ch<<" ";
}
ch++;
cout<<"\n";
}
return 0;
}

Output:

4. write a c++ program to find LCM.


Code:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter Number 1: "<<endl;
cin>>a;
cout<<"Enter Number 2: "<<endl;
cin>>b;
c=(a>b)?a:b;
while(1)
{
if(c%a==0 && c%b==0)
{
cout<<"The LCM Of "<<a<<" And "<<b<<" is "<<c<<endl;
break;
}
++c;
}
return 0;
}

Output:

5. write a program to find all roots of quadratic equation.


Code:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a,b,c,D,r1,r2,real,imag;
cout<<"Enter Value Of a: ";
cin>>a;
cout<<"Enter Value Of b: ";
cin>>b;
cout<<"Enter Value Of c: ";
cin>>c;
D=b*b-4*a*c;
if(D>0)
{
r1=(-b+sqrt(D))/(2*a);
r2=(-b-sqrt(D))/(2*a);
cout<<"Roots are real and different."<<endl;
cout<<"r1 = "<<r1<<" and r2 = "<<r2<<endl;
}
else if(D==0)
{
cout<<"Roots are real and same."<<endl;
r1=-b/(2*a);
cout<<"r1 = "<<r1<<endl;
}
else
{
real=-b/(2*a);
imag=sqrt(-D)/(2*a);
cout<<"Roots are complex and different."<<endl;
cout<<"r1 = "<<real<<"+"<<imag<<"i"<<endl;
cout<<"r2 = "<<real<<"-"<<imag<<"i";
}
return 0;
}

Output:

You might also like