LATEST UPDATES
IT CLUB IT CLUB celebrates 5th ANNIVERSARY on August 2016
Search This Blog
Coming Monday December 12th 2016...
Friday, December 9, 2016
Sample C++ Programs
Saturday, July 16, 2016
1) write a program to find the area of a Triangle.
#include<iostream>
using namespace std;
int main()
{
int area,base,height;
cout<<"Enter the base and height";
cin>>base>>height;
area=0.5*base*height;
cout<<"Area= "<<area;
}
2)Write a program to reverse a three digit number
#include<iostream>
using namespace std;
int main()
{
int n,rem,s=0;
cout<<"Enter a three digit number";
cin>>n;
while(n>0)
{
rem=n%10;
s=s*10+rem;
n=n/10;
}
cout<<s;
return 0;
}
3)Write a program to find the smallest of three numbers
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter three numbers";
cin>>a>>b>>c;
if(a<b)
{
if(a<c)
cout<<" a is small";
else
cout<<"c is small";
}
else
{
if(b<c)
cout<<"b is small";
else
cout<<"c is small";
}
}
4) Write a program to find if a number is prime or not
#include<iostream>
using namespace std;
int main()
{
int num,flag=0,i;
cout<<"Enter a Number";
cin>>num;
for(i=2;i<num;i++)
{
if(num%i==0)
{
flag=1;
break;
}
}
if(flag==0)
cout<<"Number is Prime";
else
cout<<"Number is Not Prime";
}
5)Write a program to check if a number is Even or Odd
#include<iostream>
using namespace std;
int main()
{
int n,rem;
cout<<"Enter a number";
cin>>n;
rem=n%2;
if(rem==0)
{
cout<<"Even";
}
else
{
cout<<"Odd";
}
}
6)Write a program to print a day of week
#include<iostream>
using namespace std;
int main()
{
int day;
cout<<"Enter the day of week";
cin>>day;
switch (day)
{
case 1:cout<<"Sunday";break;
case 2:cout<<"Monday";break;
case 3:cout<<"Tuesday";break;
case 4:cout<<"Wednesday";break;
case 5:cout<<"Thursday";break;
case 6:cout<<"Friday";break;
case 7:cout<<"Saturday";break;
default :cout<<"Invalid Input";
}
}
7)Write a program to find the Factorial of a givenumber.(Example 3 factorial=1*2*3 ie,6)
#include<iostream>
using namespace std;
int main()
{
int n,i,fact=1;
cout<<"Enter a number";
cin>>n;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
cout<<"Fatorial ="<<fact;
}
8)Write a program to find the sum of the digits of a threedigit number
#include<iostream>
using namespace std;
int main()
{
int n,rem,s=0,i;
cout<<"Enter a three digit number";
cin>>n;
for(i=0;i<3;i++)
{
rem=n%10;
s=s+rem;
n=n/10;
}
cout<<"Sum of digits="<<s;
}
9)Write a program to print the pattern
1
2 2
3 3 3
4 4 4 4 4
5 5 5 5 5 5
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
cout<<"\t"<<i;
}
cout<<"\n";
}
}
10)Write a program to print the pattern
A
B B
C C C
D D D D
E E E E E
#include<iostream>
using namespace std;
int main()
{
int i,j;
char ch=65;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
cout<<"\t"<<ch;
}
cout<<"\n";
ch=ch+1;
}
}
11)Write a program to print
*
* *
* * *
* * * *
* * * * *
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
cout<<"\t"<<"*";
}
cout<<"\n";
}
}
12) Write a program to produce the following outputusing nested loop
A
AB
ABC
ABCD
ABCDE
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
char ch=65;
for(j=1;j<=i;j++)
{
cout<<"\t"<<ch;
}
cout<<"\n";
ch=ch+1;
}
}
13.Write a program to find the sum of first n naturalnumbers
#include<iostream>
using namespace std;
int main()
{
int n,s=0,i;
cout<<"enter a value";
cin>>n;
for(i=1;i<=n;i++)
{
s=s+i;
}
cout<<"Sum ="<<s;
}
14.Write a program to print the Multiplication table of agiven number
#include<iostream>
using namespace std;
int main()
{
int n,i;
cout<<"enter a value";
cin>>n;
for(i=1;i<=10;i++)
{
cout<<n<<"*"<<i<<"="<<n*i;
cout<<"\n";
}
}
WORK ON PROGRESS,,,PLEASE WAIT FOR FURTHER UPDATES...
Monday, July 4, 2016
WORK ON PROGRESS,,,PLEASE WAIT FOR FURTHER UPDATES...
TECH MANTRA 2014 powered by IT CLUB
Tuesday, June 2, 2015
Subscribe to:
Posts (Atom)