#include <conio.h>
#include <stdio.h>
using namespace std;
int main ( )
{
int x=1 , a=1 ;
while ( x < 80 * 50 )
{
printf ( "%c", a);
x++ ;
}
return 0 ;
}
C++ Program Codes
Learn and share the source codes of C++ Programs
Saturday, April 4, 2015
C++ program to print payramids
#include <stdio.h>
#include <conio.h>
using namespace std ;
int main ( )
{
int a , x , n=71 , o=70 , y=1 , c ;
for ( x = 1 ; x <= 7 ; x++ )
{
for ( a = 65 ; a <=n ; a++ )
printf ( "%c", a) ;
if ( x == 2 )
o=70 ;
for ( c = 2 ; c < y ; c++ )
printf (" ");
for ( a = o ; a >=65 ; a-- )
printf ( "%c" , a) ;
printf ("\n");
n-- ;
o-- ;
y = y + 2 ;
}
return 0 ;
}
#include <conio.h>
using namespace std ;
int main ( )
{
int a , x , n=71 , o=70 , y=1 , c ;
for ( x = 1 ; x <= 7 ; x++ )
{
for ( a = 65 ; a <=n ; a++ )
printf ( "%c", a) ;
if ( x == 2 )
o=70 ;
for ( c = 2 ; c < y ; c++ )
printf (" ");
for ( a = o ; a >=65 ; a-- )
printf ( "%c" , a) ;
printf ("\n");
n-- ;
o-- ;
y = y + 2 ;
}
return 0 ;
}
C++ program to print prime numbers
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std ;
int main ( )
{
int n , i , count=0 ;
for ( n = 500 ; n <= 3000 ; n++ )
{
for ( i = 500 ; i < n ; i++ )
{
if( n % i == 0 )
break ;
}
if ( n == i )
{
count++ ;
cout << n << endl ;
}
}
cout <<" Total prime numbers are "<< count ;
return 0 ;
}
#include <conio.h>
#include <stdio.h>
using namespace std ;
int main ( )
{
int n , i , count=0 ;
for ( n = 500 ; n <= 3000 ; n++ )
{
for ( i = 500 ; i < n ; i++ )
{
if( n % i == 0 )
break ;
}
if ( n == i )
{
count++ ;
cout << n << endl ;
}
}
cout <<" Total prime numbers are "<< count ;
return 0 ;
}
C program to find out pos, neg and zeros
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main ( )
{
int num , x , pos=0 , neg=0 , zeroz=0 ;
cout <<" Enter how many numbers you want to Check ";
scanf ( "%d",&x );
while ( x > 0 )
{
scanf("%d" , &num);
if ( num > 0 )
pos++ ;
if ( num < 0 )
neg++ ;
if ( num == 0 )
zeroz++ ;
x-- ;
}
printf ( "\n You entered \n%d positive numbers \n%d negative numbers \n%d zeroes",pos,neg,zeroz);
return 0 ;
}
#include <conio.h>
#include <stdio.h>
using namespace std;
int main ( )
{
int num , x , pos=0 , neg=0 , zeroz=0 ;
cout <<" Enter how many numbers you want to Check ";
scanf ( "%d",&x );
while ( x > 0 )
{
scanf("%d" , &num);
if ( num > 0 )
pos++ ;
if ( num < 0 )
neg++ ;
if ( num == 0 )
zeroz++ ;
x-- ;
}
printf ( "\n You entered \n%d positive numbers \n%d negative numbers \n%d zeroes",pos,neg,zeroz);
return 0 ;
}
C++ program to calculate overpay of 10 employes
#include <iostream>
using namespace std ;
int main ( )
{
int employe , overtime , overpay , hours ;
for ( employe = 1 ; employe <= 10 ; employe++ )
{
cout <<" \n Enter the hours worked by a worker : ";
cin >> hours ;
if ( hours > 40 )
{
overtime = hours - 40 ;
overpay = overtime * 12 ;
cout <<" \n The overtime pay of employe is ";
cout << overpay << " rupees" << endl ;
}
else
{
cout <<" \n Their is no overtime pay ";
}
}
return 0 ;
}
using namespace std ;
int main ( )
{
int employe , overtime , overpay , hours ;
for ( employe = 1 ; employe <= 10 ; employe++ )
{
cout <<" \n Enter the hours worked by a worker : ";
cin >> hours ;
if ( hours > 40 )
{
overtime = hours - 40 ;
overpay = overtime * 12 ;
cout <<" \n The overtime pay of employe is ";
cout << overpay << " rupees" << endl ;
}
else
{
cout <<" \n Their is no overtime pay ";
}
}
return 0 ;
}
C++ program to print integers from 5 to -5
#include <iostream>
using namespace std ;
int main ( )
{
int a ;
for ( int i = 5 ; i >= -5 ; i-- )
{
cout << i << endl ;
}
return 0 ;
}
using namespace std ;
int main ( )
{
int a ;
for ( int i = 5 ; i >= -5 ; i-- )
{
cout << i << endl ;
}
return 0 ;
}
C++ program for Conversion into Octal
#include <conio.h>
#include <stdio.h>
using namespace std ;
int main ( )
{
long int i , num , arr[100] ;
printf( "Enter any number to convert it into Octal " ) ;
scanf( "%ld",&num ) ;
for ( i = 0 ; num > 8 ; i++ )
{
arr[i] = num % 8 ;
num = num / 8 ;
}
printf ( "Octal conversion is \n " ) ;
printf("%d",num) ;
while ( i>0 )
{
printf ("%d",arr[i-1]);
i-- ;
}
return 0 ;
}
#include <stdio.h>
using namespace std ;
int main ( )
{
long int i , num , arr[100] ;
printf( "Enter any number to convert it into Octal " ) ;
scanf( "%ld",&num ) ;
for ( i = 0 ; num > 8 ; i++ )
{
arr[i] = num % 8 ;
num = num / 8 ;
}
printf ( "Octal conversion is \n " ) ;
printf("%d",num) ;
while ( i>0 )
{
printf ("%d",arr[i-1]);
i-- ;
}
return 0 ;
}
C program to find ASCII values
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main ( )
{
int a ;
while ( a < 225 )
{
printf ( " %d = %c ", a , a ) ;
a++ ;
}
return 0 ;
}
#include <conio.h>
#include <stdio.h>
using namespace std;
int main ( )
{
int a ;
while ( a < 225 )
{
printf ( " %d = %c ", a , a ) ;
a++ ;
}
return 0 ;
}
C++ program to find Armstrong numbers
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main ( )
{
int a,b,c,d,e,f,res,num=1 ;
printf(" Armstrong Numbers from 1 to 500 \n") ;
while ( num <= 500 )
{
a = num % 10 ;
b = num / 10 ;
c = b % 10 ;
d = num / 10 ;
e = d % 10 ;
f = d / 10 ;
if ( num == (a*a*a) + (c*c*c) + (e*e*e) )
{
printf ( "\n %d ", num ) ;
}
num++ ;
}
return 0 ;
}
#include <conio.h>
#include <stdio.h>
using namespace std;
int main ( )
{
int a,b,c,d,e,f,res,num=1 ;
printf(" Armstrong Numbers from 1 to 500 \n") ;
while ( num <= 500 )
{
a = num % 10 ;
b = num / 10 ;
c = b % 10 ;
d = num / 10 ;
e = d % 10 ;
f = d / 10 ;
if ( num == (a*a*a) + (c*c*c) + (e*e*e) )
{
printf ( "\n %d ", num ) ;
}
num++ ;
}
return 0 ;
}
C program to add seven terms
#include <stdio.h>
#include <conio.h>
using namespace std ;
int main ( )
{
long double num , res , fres = 0 , fact = 1.0 ;
for ( num = 4.0 ; num <= 7.0 ; num++ )
{
fact = fact * num ;
res = num / fact ;
fres = fres + res ;
}
printf ( "the sum of given series is %.9Lf",fres);
return 0 ;
}
#include <conio.h>
using namespace std ;
int main ( )
{
long double num , res , fres = 0 , fact = 1.0 ;
for ( num = 4.0 ; num <= 7.0 ; num++ )
{
fact = fact * num ;
res = num / fact ;
fres = fres + res ;
}
printf ( "the sum of given series is %.9Lf",fres);
return 0 ;
}
C++ program to swap the values of two integers.
#include <iostream>
using namespace std;
int main ( )
{
int a , b , c ;
cout<<" Value of a is : ";
cin>> a;
cout<<" \n Value of b is : ";
cin>> b;
c=a;
a=b;
b=c;
cout<<" \n Values had been interchanged \n\n";
cout<< " Value of a becomes : " << a << endl;
cout<< " Values of b becomes : " << b << endl;
return 0;
}
using namespace std;
int main ( )
{
int a , b , c ;
cout<<" Value of a is : ";
cin>> a;
cout<<" \n Value of b is : ";
cin>> b;
c=a;
a=b;
b=c;
cout<<" \n Values had been interchanged \n\n";
cout<< " Value of a becomes : " << a << endl;
cout<< " Values of b becomes : " << b << endl;
return 0;
}
C++ program to sum the two numbers and repeats it unless sum becomes greater then 10
#include <iostream>
using namespace std ;
int main ( )
{
int a,b,c ;
do
{
cout <<" Enter the first number ";
cin >> a ;
cout <<" Enter the Second number ";
cin >> b ;
c=a+b;
cout << c << endl ;
}while (c<10);
return 0 ;
}
using namespace std ;
int main ( )
{
int a,b,c ;
do
{
cout <<" Enter the first number ";
cin >> a ;
cout <<" Enter the Second number ";
cin >> b ;
c=a+b;
cout << c << endl ;
}while (c<10);
return 0 ;
}
C++ Program to find the grade of numbers obtained
#include <iostream>
using namespace std;
int main ( )
{
int marks;
cout <<" Enter the marks you gained \n";
cin >> marks;
if ( marks >= 0 && marks <50 )
{
cout <<" Mubarik ho bhai! Aap ko supply say nawaza gia hay ";
}
else if ( marks >= 50 && marks < 60 )
{
cout <<" You got D grade marks " ;
}
else if ( marks >= 60 && marks < 70 )
{
cout <<" You got c grade marks ";
}
else if ( marks >= 70 && marks < 80 )
{
cout <<" You got B grade marks ";
}
else if ( marks >= 80 && marks < 90 )
{
cout <<" You got a grade marks ";
}
else if ( marks >= 90 && marks < 100 )
{
cout <<" Wah g wah bchay ka A+ grade aya hay ";
}
return 0;
}
using namespace std;
int main ( )
{
int marks;
cout <<" Enter the marks you gained \n";
cin >> marks;
if ( marks >= 0 && marks <50 )
{
cout <<" Mubarik ho bhai! Aap ko supply say nawaza gia hay ";
}
else if ( marks >= 50 && marks < 60 )
{
cout <<" You got D grade marks " ;
}
else if ( marks >= 60 && marks < 70 )
{
cout <<" You got c grade marks ";
}
else if ( marks >= 70 && marks < 80 )
{
cout <<" You got B grade marks ";
}
else if ( marks >= 80 && marks < 90 )
{
cout <<" You got a grade marks ";
}
else if ( marks >= 90 && marks < 100 )
{
cout <<" Wah g wah bchay ka A+ grade aya hay ";
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C Program to reverse the number
#include <stdio.h>
#include <conio.h>
using namespace std;
int main ()
{
int num,a,b,c,d,e,d1,d2,d3,d4,d5;
printf(" Program to reverse the five digits number \n\n");
printf(" Enter a five digits number \n");
scanf("%d",&num);
a=num/10;
d5=num%10;
b=a/10;
d4=a%10;
c=b/10;
d3=b%10;
d=c/10;
d2=c%10;
e=d/10;
d1=d%10;
printf(" \n Reverse Number = %d%d%d%d%d",d5,d4,d3,d2,d1);
printf(" \n Reverse Number is not Equal to Original number ");
return 0;
}
#include <conio.h>
using namespace std;
int main ()
{
int num,a,b,c,d,e,d1,d2,d3,d4,d5;
printf(" Program to reverse the five digits number \n\n");
printf(" Enter a five digits number \n");
scanf("%d",&num);
a=num/10;
d5=num%10;
b=a/10;
d4=a%10;
c=b/10;
d3=b%10;
d=c/10;
d2=c%10;
e=d/10;
d1=d%10;
printf(" \n Reverse Number = %d%d%d%d%d",d5,d4,d3,d2,d1);
printf(" \n Reverse Number is not Equal to Original number ");
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to make an inverted paramid with space
#include <iostream>
using namespace std ;
int main ( )
{
for ( int i=1 ; i <=10 ; i++ )
{
for ( int a=1 ; a<i ; a++ )
{
cout << " ";
}
for ( int b=i ; b<=10 ; b++ )
{
cout << b ;
}
cout << endl ;
}
return 0;
}
using namespace std ;
int main ( )
{
for ( int i=1 ; i <=10 ; i++ )
{
for ( int a=1 ; a<i ; a++ )
{
cout << " ";
}
for ( int b=i ; b<=10 ; b++ )
{
cout << b ;
}
cout << endl ;
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to know how to use nested if
#include <iostream>
using namespace std;
int main ( )
{
int a;
cout <<" Enter a number ";
cin >> a;
if ( a%5 == 0 )
{
if ( a%3 == 0 )
{
cout <<" Number is divisible by both 3 & 5 \n";
}
else
{
cout <<" Number is divisible by 5 \n";
}
}
else
{
cout <<" Number is not divisible by 5 \n";
}
return 0;
}
using namespace std;
int main ( )
{
int a;
cout <<" Enter a number ";
cin >> a;
if ( a%5 == 0 )
{
if ( a%3 == 0 )
{
cout <<" Number is divisible by both 3 & 5 \n";
}
else
{
cout <<" Number is divisible by 5 \n";
}
}
else
{
cout <<" Number is not divisible by 5 \n";
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to findout either the given character is vowel or not
#include <iostream>
using namespace std;
int main ( )
{
char a;
cout <<" Enter a character \n";
cin >> a;
if ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
{
cout <<" character is vowel ";
}
else
{
cout <<" Character is not a vowel ";
}
return 0;
}
using namespace std;
int main ( )
{
char a;
cout <<" Enter a character \n";
cin >> a;
if ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
{
cout <<" character is vowel ";
}
else
{
cout <<" Character is not a vowel ";
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to findout either the given character is vowel or not using Switch
#include <iostream>
using namespace std;
int main ( )
{
char a;
cout <<" Enter a character \n ";
cin >> a;
switch ( a )
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' :
cout <<" Character is a vowel alphabet ";
break ;
default :
cout <<" Character is not a vowel ";
}
return 0;
}
using namespace std;
int main ( )
{
char a;
cout <<" Enter a character \n ";
cin >> a;
switch ( a )
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' :
cout <<" Character is a vowel alphabet ";
break ;
default :
cout <<" Character is not a vowel ";
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find weather the Area is larger or Parameter
#include <iostream>
using namespace std ;
int main ( )
{
int l , b , a , p ;
cout <<" Enter the length " ;
cin >> l ;
cout <<" Enter the breadth " ;
cin >> b ;
a = l * b ;
p = 2 * ( l + b ) ;
cout <<" Area of rectangle is " << a << endl ;
cout <<" Parameter of rectangle is " << p << endl ;
if ( a > p )
{
cout <<" \n Area of the rectangle is greater then its Parameter " ;
}
else
{
cout <<" \n Parameter of rectangle is greater then its Area " ;
}
return 0 ;
}
using namespace std ;
int main ( )
{
int l , b , a , p ;
cout <<" Enter the length " ;
cin >> l ;
cout <<" Enter the breadth " ;
cin >> b ;
a = l * b ;
p = 2 * ( l + b ) ;
cout <<" Area of rectangle is " << a << endl ;
cout <<" Parameter of rectangle is " << p << endl ;
if ( a > p )
{
cout <<" \n Area of the rectangle is greater then its Parameter " ;
}
else
{
cout <<" \n Parameter of rectangle is greater then its Area " ;
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C Program to find the sum of digits of five digits number
#include <conio.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int main ()
{
int num,sum,a,b,c,d,e,d1,d2,d3,d4,d5;
printf(" Program to calculate the sum of digits of a five digit number \n\n");
printf(" Enter the Five Digits Number \n");
scanf("%d",&num);
a=num/10;
d5=num%10;
b=a/10;
d4=a%10;
c=b/10;
d3=b%10;
d=c/10;
d2=c%10;
e=d/10;
d1=d%10;
sum=d1+d2+d3+d4+d5;
printf("\n Sum of digits of given number is %d",sum);
return 0;
}
#include <stdio.h>
#include <iostream>
using namespace std;
int main ()
{
int num,sum,a,b,c,d,e,d1,d2,d3,d4,d5;
printf(" Program to calculate the sum of digits of a five digit number \n\n");
printf(" Enter the Five Digits Number \n");
scanf("%d",&num);
a=num/10;
d5=num%10;
b=a/10;
d4=a%10;
c=b/10;
d3=b%10;
d=c/10;
d2=c%10;
e=d/10;
d1=d%10;
sum=d1+d2+d3+d4+d5;
printf("\n Sum of digits of given number is %d",sum);
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find the largast number
#include <iostream>
using namespace std;
int main ( )
{
int a,s,d;
cout <<" Enter the three different numbers \n";
cin >> a >> s >> d ;
if ( a>s )
{
if ( a>d )
{
cout <<" The largest number is a " ;
}
else
{
cout <<" Largest number is d " ;
}
}
else
{
if ( s>d )
{
cout <<" Largest number is s " ;
}
else
{
cout <<" Largest number is d " ;
}
}
return 0;
}
using namespace std;
int main ( )
{
int a,s,d;
cout <<" Enter the three different numbers \n";
cin >> a >> s >> d ;
if ( a>s )
{
if ( a>d )
{
cout <<" The largest number is a " ;
}
else
{
cout <<" Largest number is d " ;
}
}
else
{
if ( s>d )
{
cout <<" Largest number is s " ;
}
else
{
cout <<" Largest number is d " ;
}
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find the gross sallery of a person
#include <iostream>
using namespace std;
int main ()
{
float sallery;
float grosssallery;
cout<<" Program to calculate Rameez's gross sallery with addition of all allownces! \n";
cout<<" Enter Rameez's basic sallery in Rupees \n";
cin>> sallery;
grosssallery= sallery + (sallery/100)*40 + (sallery/100)*20;
cout<<" Rameez's Gross sallery in Rupees after addition of allowances will be \n";
cout<< grosssallery;
return 0;
}
using namespace std;
int main ()
{
float sallery;
float grosssallery;
cout<<" Program to calculate Rameez's gross sallery with addition of all allownces! \n";
cout<<" Enter Rameez's basic sallery in Rupees \n";
cin>> sallery;
grosssallery= sallery + (sallery/100)*40 + (sallery/100)*20;
cout<<" Rameez's Gross sallery in Rupees after addition of allowances will be \n";
cout<< grosssallery;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find the grade of numbers obtained
#include <iostream>
using namespace std;
int main ( )
{
int marks;
cout <<" Enter the marks you gained \n";
cin >> marks;
if ( marks >= 0 && marks <50 )
{
cout <<" Mubarik ho bhai! Aap ko supply say nawaza gia hay ";
}
else if ( marks >= 50 && marks < 60 )
{
cout <<" You got D grade marks " ;
}
else if ( marks >= 60 && marks < 70 )
{
cout <<" You got c grade marks ";
}
else if ( marks >= 70 && marks < 80 )
{
cout <<" You got B grade marks ";
}
else if ( marks >= 80 && marks < 90 )
{
cout <<" You got a grade marks ";
}
else if ( marks >= 90 && marks < 100 )
{
cout <<" Wah g wah bchay ka A+ grade aya hay ";
}
return 0;
}
using namespace std;
int main ( )
{
int marks;
cout <<" Enter the marks you gained \n";
cin >> marks;
if ( marks >= 0 && marks <50 )
{
cout <<" Mubarik ho bhai! Aap ko supply say nawaza gia hay ";
}
else if ( marks >= 50 && marks < 60 )
{
cout <<" You got D grade marks " ;
}
else if ( marks >= 60 && marks < 70 )
{
cout <<" You got c grade marks ";
}
else if ( marks >= 70 && marks < 80 )
{
cout <<" You got B grade marks ";
}
else if ( marks >= 80 && marks < 90 )
{
cout <<" You got a grade marks ";
}
else if ( marks >= 90 && marks < 100 )
{
cout <<" Wah g wah bchay ka A+ grade aya hay ";
}
return 0;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs
C++ Program to find the grade of numbers obtained
#include <iostream>
using namespace std;
int main ( )
{
int marks;
cout <<" Enter the marks you gained \n";
cin >> marks;
if ( marks >= 0 && marks <50 )
{
cout <<" Mubarik ho bhai! Aap ko supply say nawaza gia hay ";
}
else if ( marks >= 50 && marks < 60 )
{
cout <<" You got D grade marks " ;
}
else if ( marks >= 60 && marks < 70 )
{
cout <<" You got c grade marks ";
}
else if ( marks >= 70 && marks < 80 )
{
cout <<" You got B grade marks ";
}
else if ( marks >= 80 && marks < 90 )
{
cout <<" You got a grade marks ";
}
else if ( marks >= 90 && marks < 100 )
{
cout <<" Wah g wah bchay ka A+ grade aya hay ";
}
return 0;
}
using namespace std;
int main ( )
{
int marks;
cout <<" Enter the marks you gained \n";
cin >> marks;
if ( marks >= 0 && marks <50 )
{
cout <<" Mubarik ho bhai! Aap ko supply say nawaza gia hay ";
}
else if ( marks >= 50 && marks < 60 )
{
cout <<" You got D grade marks " ;
}
else if ( marks >= 60 && marks < 70 )
{
cout <<" You got c grade marks ";
}
else if ( marks >= 70 && marks < 80 )
{
cout <<" You got B grade marks ";
}
else if ( marks >= 80 && marks < 90 )
{
cout <<" You got a grade marks ";
}
else if ( marks >= 90 && marks < 100 )
{
cout <<" Wah g wah bchay ka A+ grade aya hay ";
}
return 0;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs
C++ Program to find the given number is Even or Odd
#include <iostream>
using namespace std;
int main ( )
{
int a;
int b;
cout<<" ENTER YOUR NUMBER \n";
cin>> a;
if (a%2==0)
{
cout<<" GIVEN NUMBER IS EVEN ";
}
else
{
cout<<" GIVEN NUMBER IS ODD \n";
}
return 0;
}
using namespace std;
int main ( )
{
int a;
int b;
cout<<" ENTER YOUR NUMBER \n";
cin>> a;
if (a%2==0)
{
cout<<" GIVEN NUMBER IS EVEN ";
}
else
{
cout<<" GIVEN NUMBER IS ODD \n";
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find the given number is Even or Odd using Switch
#include <iostream>
using namespace std;
int main ( )
{
int num;
cout <<" Enter a number ";
cin >> num;
switch ( num % 2 )
{
case 0 :
cout <<" The number is even ";
break ;
case 1 :
cout <<" The number is odd ";
break ;
}
return 0 ;
}
using namespace std;
int main ( )
{
int num;
cout <<" Enter a number ";
cin >> num;
switch ( num % 2 )
{
case 0 :
cout <<" The number is even ";
break ;
case 1 :
cout <<" The number is odd ";
break ;
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C Program to find the day on 1st january of any year
#include<stdio.h>
#include<conio.h>
int main()
{
int y,n,i,r=1900;
long s=0;
printf("\nEnter the year");
scanf("%d",&y);
for(i=r;i<y;i++)
{
if(i%4==0)
s=s+366;
else
s=s+365;
}
n=s%7;
printf("\nJanuary 1st of %d was ",y);
if(n==1)
printf("Monday");
else
if(n==2)
printf("Tuesday");
else
if(n==3)
printf("Wednesday");
else
if(n==4)
printf("Thursday");
else
if(n==5)
printf("Friday");
else
if(n==6)
printf("Saturday");
else
if(n==7)
printf("Sunday");
return 0 ;
}
#include<conio.h>
int main()
{
int y,n,i,r=1900;
long s=0;
printf("\nEnter the year");
scanf("%d",&y);
for(i=r;i<y;i++)
{
if(i%4==0)
s=s+366;
else
s=s+365;
}
n=s%7;
printf("\nJanuary 1st of %d was ",y);
if(n==1)
printf("Monday");
else
if(n==2)
printf("Tuesday");
else
if(n==3)
printf("Wednesday");
else
if(n==4)
printf("Thursday");
else
if(n==5)
printf("Friday");
else
if(n==6)
printf("Saturday");
else
if(n==7)
printf("Sunday");
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to find that the triangle is valid or not
#include <iostream>
using namespace std ;
int main ( )
{
int a , b , c , angle ;
cout << " Enter the first angle " ;
cin >> a ;
cout << " Enter the second angle " ;
cin >> b ;
cout << " Enter the third angle " ;
cin >> c ;
angle = a + b + c ;
if ( angle == 180 )
{
cout <<" The triangle is a valid ";
}
else
{
cout <<" The triangle is not a valid ";
}
return 0 ;
}
using namespace std ;
int main ( )
{
int a , b , c , angle ;
cout << " Enter the first angle " ;
cin >> a ;
cout << " Enter the second angle " ;
cin >> b ;
cout << " Enter the third angle " ;
cin >> c ;
angle = a + b + c ;
if ( angle == 180 )
{
cout <<" The triangle is a valid ";
}
else
{
cout <<" The triangle is not a valid ";
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find that seller made profit or loss or how much he made
#include <iostream>
using namespace std ;
int main ( )
{
int cp , sp , loss , prof ;
cout <<" Enter the Cost Price ";
cin >> cp ;
cout <<" Enter the selling price ";
cin >> sp ;
if ( cp < sp )
{
prof = sp - cp ;
cout <<" Seller has made the Profit of = " << prof << " rupees " << endl ;
}
else if ( cp > sp )
{
loss = cp - sp ;
cout <<" Seller has made the lost = " << loss << " rupees " << endl ;
}
return 0 ;
}
using namespace std ;
int main ( )
{
int cp , sp , loss , prof ;
cout <<" Enter the Cost Price ";
cin >> cp ;
cout <<" Enter the selling price ";
cin >> sp ;
if ( cp < sp )
{
prof = sp - cp ;
cout <<" Seller has made the Profit of = " << prof << " rupees " << endl ;
}
else if ( cp > sp )
{
loss = cp - sp ;
cout <<" Seller has made the lost = " << loss << " rupees " << endl ;
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to find that all points lies on same line or not
#include <iostream>
using namespace std ;
int main ( )
{
int x1 , y1 , x2 , y2 , x3 , y3 , s1 , s2 ;
cout <<" Enter the Value of x1 ";
cin >> x1 ;
cout <<" Enter the value of x2 ";
cin >> x2 ;
cout <<" Enter the value of x3 ";
cin >> x3 ;
cout <<" Enter the value of y1 ";
cin >> y1 ;
cout <<" Enter the value of y2 ";
cin >> y2 ;
cout <<" Enter the value of y3 ";
cin >> y3 ;
s1 = ( y2 - y1 ) + ( x2 - x1 );
s2 = ( y3 - y2 ) + ( x3 - x2 );
if( s1 == s2 )
{
cout <<" All these points falls on same line ";
}
else
{
cout <<" All these points does not falls on same line ";
}
return 0 ;
}
using namespace std ;
int main ( )
{
int x1 , y1 , x2 , y2 , x3 , y3 , s1 , s2 ;
cout <<" Enter the Value of x1 ";
cin >> x1 ;
cout <<" Enter the value of x2 ";
cin >> x2 ;
cout <<" Enter the value of x3 ";
cin >> x3 ;
cout <<" Enter the value of y1 ";
cin >> y1 ;
cout <<" Enter the value of y2 ";
cin >> y2 ;
cout <<" Enter the value of y3 ";
cin >> y3 ;
s1 = ( y2 - y1 ) + ( x2 - x1 );
s2 = ( y3 - y2 ) + ( x3 - x2 );
if( s1 == s2 )
{
cout <<" All these points falls on same line ";
}
else
{
cout <<" All these points does not falls on same line ";
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C Program to find reverse of number and also that it is equal to original or not
#include <iostream>
#include <stdio.h>
#include <conio.h>
int main( )
{
int last_digit, number, next_digit, rev_num;
printf ("Enter the five-digit number that has to be reversed and checked for equality:");
scanf("%d", &number);
last_digit = number - ((number / 10) * 10);
rev_num = last_digit;
next_digit = (number / 10) - ((number / 100) * 10);
rev_num = (rev_num * 10) + next_digit;
next_digit = (number / 100) - ((number / 1000) * 10);
rev_num = (rev_num * 10) + next_digit;
next_digit = (number / 1000) - ((number / 10000) * 10);
rev_num = (rev_num * 10) + next_digit;
next_digit = (number / 10000) - ((number / 100000) * 10);
rev_num = (rev_num * 10) + next_digit;
printf ("The Reversed Number is: %d",rev_num);
if (rev_num==number)
{
printf("\nEntered number and reversed number are equal\n");
}
else
{
printf("\nEntered number and reversed number are not equal\n");
}
return 0 ;
}
#include <stdio.h>
#include <conio.h>
int main( )
{
int last_digit, number, next_digit, rev_num;
printf ("Enter the five-digit number that has to be reversed and checked for equality:");
scanf("%d", &number);
last_digit = number - ((number / 10) * 10);
rev_num = last_digit;
next_digit = (number / 10) - ((number / 100) * 10);
rev_num = (rev_num * 10) + next_digit;
next_digit = (number / 100) - ((number / 1000) * 10);
rev_num = (rev_num * 10) + next_digit;
next_digit = (number / 1000) - ((number / 10000) * 10);
rev_num = (rev_num * 10) + next_digit;
next_digit = (number / 10000) - ((number / 100000) * 10);
rev_num = (rev_num * 10) + next_digit;
printf ("The Reversed Number is: %d",rev_num);
if (rev_num==number)
{
printf("\nEntered number and reversed number are equal\n");
}
else
{
printf("\nEntered number and reversed number are not equal\n");
}
return 0 ;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs
C++ program to find out the yaer is leap or not
#include <iostream>
using namespace std ;
int main ( )
{
int year ;
cout <<" Enter the year ";
cin >> year ;
if ( year % 4 == 0 )
{
cout <<" It is a leap Year ";
}
else
{
cout <<" It is not a leap yaer ";
}
return 0 ;
}
using namespace std ;
int main ( )
{
int year ;
cout <<" Enter the year ";
cin >> year ;
if ( year % 4 == 0 )
{
cout <<" It is a leap Year ";
}
else
{
cout <<" It is not a leap yaer ";
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find out the sum of first and 4th digit of four digits number
#include <stdio.h>
#include <conio.h>
using namespace std;
int main ()
{
int num,sum,a,b,c,d,d1,d2,d3,d4;
printf(" Enter a four digits number \n");
scanf("%d",&num);
a=num/10;
d4=num%10;
b=a/10;
d3=a%10;
c=b/10;
d2=b%10;
d=c/10;
d1=c%10;
sum=d1+d4;
printf(" Sum of first & last digit = %d",sum);
return 0;
}
#include <conio.h>
using namespace std;
int main ()
{
int num,sum,a,b,c,d,d1,d2,d3,d4;
printf(" Enter a four digits number \n");
scanf("%d",&num);
a=num/10;
d4=num%10;
b=a/10;
d3=a%10;
c=b/10;
d2=b%10;
d=c/10;
d1=c%10;
sum=d1+d4;
printf(" Sum of first & last digit = %d",sum);
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find out the maximum number using array.
#include <iostream>
using namespace std ;
int main ( )
{
int a[5],max;
for ( int i = 0 ; i<5 ; i++ )
{
cout << " Enter a number ";
cin >> a[i];
}
max= a[0];
for ( int i=1 ; i<5 ; i++ )
{
if ( a[i] > max )
max= a[i];
}
cout <<" MAXIMUM NUMBER IS "<< max ;
return 0;
}
using namespace std ;
int main ( )
{
int a[5],max;
for ( int i = 0 ; i<5 ; i++ )
{
cout << " Enter a number ";
cin >> a[i];
}
max= a[0];
for ( int i=1 ; i<5 ; i++ )
{
if ( a[i] > max )
max= a[i];
}
cout <<" MAXIMUM NUMBER IS "<< max ;
return 0;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs
C++ Program to find out the list of prime numbers.
#include <iostream>
using namespace std ;
int main ( )
{
int n , i ;
for ( n=2 ; n<= 100 ; n++ )
{
for ( i=2 ; i<n ; i++ )
{
if ( n%i == 0)
break ;
}
if ( i == n )
{
cout << n << endl ;
}
}
return 0 ;
}
using namespace std ;
int main ( )
{
int n , i ;
for ( n=2 ; n<= 100 ; n++ )
{
for ( i=2 ; i<n ; i++ )
{
if ( n%i == 0)
break ;
}
if ( i == n )
{
cout << n << endl ;
}
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find out the cost price of one item
#include <iostream>
using namespace std;
int main ( )
{
int sp,tp,cp,cp1;
cout << " Program to calculate the price of one item \n";
cout << " \n Enter the total selling price of 15 items : ";
cin >> sp;
cout << " \n Enter profit on selling these items : ";
cin >> tp;
cp=sp-tp;
cp1=cp/15;
cout << " \n The price of each item is : " << cp1 ;
return 0;
}
using namespace std;
int main ( )
{
int sp,tp,cp,cp1;
cout << " Program to calculate the price of one item \n";
cout << " \n Enter the total selling price of 15 items : ";
cin >> sp;
cout << " \n Enter profit on selling these items : ";
cin >> tp;
cp=sp-tp;
cp1=cp/15;
cout << " \n The price of each item is : " << cp1 ;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to find out the absolute value of number
#include <iostream>
using namespace std ;
int main ( )
{
int a=0 , b ;
cout <<" Enter the Number ";
cin >> a ;
if ( a < 0 )
{
b = a * -1 ;
cout <<" The absolute value of given number is " << cout << b ;
}
else
{
b = a ;
cout <<" The absolute value of given number is " << cout << b ;
}
return 0 ;
}
using namespace std ;
int main ( )
{
int a=0 , b ;
cout <<" Enter the Number ";
cin >> a ;
if ( a < 0 )
{
b = a * -1 ;
cout <<" The absolute value of given number is " << cout << b ;
}
else
{
b = a ;
cout <<" The absolute value of given number is " << cout << b ;
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to find out how many currency notes should a cashier be given
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main ( )
{
int ammount,ten,fifty,hunderd;
cout<<" Program to show total number of notes that \n\n";
cout<<" Cashier will give to withdrawal \n";
cout<<" Enter ammount to be with drawn : \n";
cin>> ammount;
ten=ammount/10;
fifty=ammount/50;
hunderd=ammount/100;
printf("The Cashier will give you\n %d Notes of Tens \n OR \n %d Notes of Fifties \n OR \n %d Notes of Hunderds",ten,fifty,hunderd);
return 0;
}
#include <conio.h>
#include <iostream>
using namespace std;
int main ( )
{
int ammount,ten,fifty,hunderd;
cout<<" Program to show total number of notes that \n\n";
cout<<" Cashier will give to withdrawal \n";
cout<<" Enter ammount to be with drawn : \n";
cin>> ammount;
ten=ammount/10;
fifty=ammount/50;
hunderd=ammount/100;
printf("The Cashier will give you\n %d Notes of Tens \n OR \n %d Notes of Fifties \n OR \n %d Notes of Hunderds",ten,fifty,hunderd);
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to find out different dimensions of rectangle or circle
#include <iostream>
using namespace std;
int main ()
{
float length, breadth, radius;
float aofr, perimeter, aofc, circumference;
cout<<" Program to calculate area and perimeter of a rectangle & \n";
cout<<" Area and Circumference of a circle \n\n";
cout<<" Enter the length of Rectangle \n";
cin>> length;
cout<<" Enter the breadth of that Rectangle \n";
cin>> breadth;
cout<<" Now enter the radius of circle \n";
cin>> radius;
aofr=length*breadth;
cout<<" Area of Rectangle is \n";
cout<< aofr;
perimeter=(2*length)+(2*breadth);
cout<<" \n Perimeter of rectangle is \n";
cout<< perimeter;
aofc= 3.14*(radius*radius);
cout<<" \n Area of Circle is \n";
cout<< aofc;
circumference=2*3.14*radius;
cout<<" \n Circumference of Circle is \n";
cout<< circumference;
return 0;
}
using namespace std;
int main ()
{
float length, breadth, radius;
float aofr, perimeter, aofc, circumference;
cout<<" Program to calculate area and perimeter of a rectangle & \n";
cout<<" Area and Circumference of a circle \n\n";
cout<<" Enter the length of Rectangle \n";
cin>> length;
cout<<" Enter the breadth of that Rectangle \n";
cin>> breadth;
cout<<" Now enter the radius of circle \n";
cin>> radius;
aofr=length*breadth;
cout<<" Area of Rectangle is \n";
cout<< aofr;
perimeter=(2*length)+(2*breadth);
cout<<" \n Perimeter of rectangle is \n";
cout<< perimeter;
aofc= 3.14*(radius*radius);
cout<<" \n Area of Circle is \n";
cout<< aofc;
circumference=2*3.14*radius;
cout<<" \n Circumference of Circle is \n";
cout<< circumference;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to find out aggrigate and percentage of 5 subjects.
#include <iostream>
using namespace std;
int main ()
{
float s1,s2,s3,s4,s5;
float agg, percentage;
cout<<" Program to calculate aggregate & Percentage of marks \n\n";
cout<<" gained by student in five different subjects out of 100 \n";
cout<<" Enter The marks of first Subject \n";
cin>> s1;
cout<<" Enter The marks of Second Subject \n";
cin>> s2;
cout<<" Enter The marks of Third Subject \n";
cin>> s3;
cout<<" Enter The marks of Fourth Subject \n";
cin>> s4;
cout<<" Enter The marks of Fifth Subject \n";
cin>> s5;
agg=s1+s2+s3+s4+s5;
cout<<"\n Aggrigate is \n";
cout<< agg;
percentage=(s1+s2+s3+s4+s5)/500*100;
cout<<"\n percentage is \n";
cout<< percentage;
return 0;
}
using namespace std;
int main ()
{
float s1,s2,s3,s4,s5;
float agg, percentage;
cout<<" Program to calculate aggregate & Percentage of marks \n\n";
cout<<" gained by student in five different subjects out of 100 \n";
cout<<" Enter The marks of first Subject \n";
cin>> s1;
cout<<" Enter The marks of Second Subject \n";
cin>> s2;
cout<<" Enter The marks of Third Subject \n";
cin>> s3;
cout<<" Enter The marks of Fourth Subject \n";
cin>> s4;
cout<<" Enter The marks of Fifth Subject \n";
cin>> s5;
agg=s1+s2+s3+s4+s5;
cout<<"\n Aggrigate is \n";
cout<< agg;
percentage=(s1+s2+s3+s4+s5)/500*100;
cout<<"\n percentage is \n";
cout<< percentage;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to find cube of number
#include<conio.h>
#include<iostream>
using namespace std;
int main ()
{
int a,b;
cout<<"Enter the number\n";
cin>>a;
b=a*a*a;
cout<<"Result in cube is\n";
cout<<b;
return 0;
}
#include<iostream>
using namespace std;
int main ()
{
int a,b;
cout<<"Enter the number\n";
cin>>a;
b=a*a*a;
cout<<"Result in cube is\n";
cout<<b;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to draw a rectangle
#include<iostream>
using namespace std;
main()
{
int squareHeight, squareWidth;
cout<< "Enter Height: ";
cin>> squareHeight;
cout<< "Enter Widht: ";
cin>> squareWidth;
for(int width=1; width<=squareHeight; width++)
{
if(width <= 1)
for(int width=1; width<=squareWidth; width++)
{
cout<< "*";
}
else if(width<squareHeight)
{
cout<< endl;
for(int width2=1; width2<=squareWidth; width2++)
{
if(width2==1 || width2==squareWidth)
cout<< "*";
else
cout<< " ";
} //end of for variable width2
}// end of else if
else
{
cout<< endl;
for(int width3=1; width3<=squareWidth; width3++)
{
cout<<"*";
}//end of for having variable width3
}// end of else
}// end of first for loop
}
using namespace std;
main()
{
int squareHeight, squareWidth;
cout<< "Enter Height: ";
cin>> squareHeight;
cout<< "Enter Widht: ";
cin>> squareWidth;
for(int width=1; width<=squareHeight; width++)
{
if(width <= 1)
for(int width=1; width<=squareWidth; width++)
{
cout<< "*";
}
else if(width<squareHeight)
{
cout<< endl;
for(int width2=1; width2<=squareWidth; width2++)
{
if(width2==1 || width2==squareWidth)
cout<< "*";
else
cout<< " ";
} //end of for variable width2
}// end of else if
else
{
cout<< endl;
for(int width3=1; width3<=squareWidth; width3++)
{
cout<<"*";
}//end of for having variable width3
}// end of else
}// end of first for loop
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to design a calculator with operation choice for user.
#include <iostream>
#include <conio.h>
using namespace std ;
int main ( )
{
int a ;
do
{
cout <<" rehanprogrammer.blogspot.com \n " ;
cout <<" \n Enter 1 for Addition \n " ;
cout <<" Enter 2 for Subtraction \n ";
cout <<" Enter 3 for Multiplicatin \n ";
cout <<" Enter 4 for Division \n ";
cout <<" Enter 5 to exit the program \n ";
cout <<" \n Now Enter your desired Operation ";
cin >> a ;
switch ( a )
{
case 1:
int s , d ;
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Addition of two numbers is " << s+d << endl ;
break ;
case 2:
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Subtraction of two numbers is " << s-d << endl ;
break ;
case 3:
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Multiplication of two numbers is " << s*d << endl ;
break ;
case 4:
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Division of two numbers is " << s/d << endl ;
break ;
}
} while(a!=5) ;
return 0 ;
}
#include <conio.h>
using namespace std ;
int main ( )
{
int a ;
do
{
cout <<" rehanprogrammer.blogspot.com \n " ;
cout <<" \n Enter 1 for Addition \n " ;
cout <<" Enter 2 for Subtraction \n ";
cout <<" Enter 3 for Multiplicatin \n ";
cout <<" Enter 4 for Division \n ";
cout <<" Enter 5 to exit the program \n ";
cout <<" \n Now Enter your desired Operation ";
cin >> a ;
switch ( a )
{
case 1:
int s , d ;
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Addition of two numbers is " << s+d << endl ;
break ;
case 2:
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Subtraction of two numbers is " << s-d << endl ;
break ;
case 3:
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Multiplication of two numbers is " << s*d << endl ;
break ;
case 4:
cout <<" Enter the first value : \n";
cin >> s ;
cout <<" Enter the Second value : \n ";
cin >> d ;
cout <<" Division of two numbers is " << s/d << endl ;
break ;
}
} while(a!=5) ;
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to create flash
#include<iostream>
#include<unistd.h>
using namespace std;
main()
{
int i;
for(i=0;i<=100000;i++)
{
cout<<"Loading......."<<i<<"%\r";
usleep(100000);
}
return 0;
}
#include<unistd.h>
using namespace std;
main()
{
int i;
for(i=0;i<=100000;i++)
{
cout<<"Loading......."<<i<<"%\r";
usleep(100000);
}
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ Program to convert feets into inches
#include <conio.h>
#include <iostream>
using namespace std;
int main ()
{
float feet,inches;
cout<<" ENTER LENGHT IN INCHES\n";
cin>> inches;
feet=inches/12;
cout<<" LENGTH IN FEET is \n";
cout<< feet;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
float feet,inches;
cout<<" ENTER LENGHT IN INCHES\n";
cin>> inches;
feet=inches/12;
cout<<" LENGTH IN FEET is \n";
cout<< feet;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to convert fahrenheit into Celsius.
#include <iostream>
using namespace std;
int main ()
{
float tf;
float tc;
cout<<" Program to convert Fahrenheit into Celcius \n\n";
cout<<" Enter the temperature in Fahrenheit \n";
cin>> tf;
tc=(tf-32)*5/9;
cout<<" Temperature in Celsius is \n" << tc;
}
using namespace std;
int main ()
{
float tf;
float tc;
cout<<" Program to convert Fahrenheit into Celcius \n\n";
cout<<" Enter the temperature in Fahrenheit \n";
cin>> tf;
tc=(tf-32)*5/9;
cout<<" Temperature in Celsius is \n" << tc;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to convert and print this distance in meters, feet, inches, cms
#include <iostream>
using namespace std;
int main ()
{
float km;
float meters, feets, inches, cms;
cout<<" Program to convert kilometers into various units! \n\n";
cout<<" ENTER THE DISTANCE BETWEEN TWO CITIES IN Km \n";
cin>> km;
meters=km*1000;
cout<<" DISTANCE IN METERS IS \n";
cout<< meters;
feets=km*3280.84;
cout<<" \n DISTANCE IN FEETS IS \n";
cout<< feets;
inches=km*39370.1;
cout<<" \n DISTANCE IN INCHES IS \n";
cout<< inches;
cms=km*100000;
cout<<" \n DISTANCE IN CENTIMETERES IS \n";
cout<< cms;
return 0;
}
using namespace std;
int main ()
{
float km;
float meters, feets, inches, cms;
cout<<" Program to convert kilometers into various units! \n\n";
cout<<" ENTER THE DISTANCE BETWEEN TWO CITIES IN Km \n";
cin>> km;
meters=km*1000;
cout<<" DISTANCE IN METERS IS \n";
cout<< meters;
feets=km*3280.84;
cout<<" \n DISTANCE IN FEETS IS \n";
cout<< feets;
inches=km*39370.1;
cout<<" \n DISTANCE IN INCHES IS \n";
cout<< inches;
cms=km*100000;
cout<<" \n DISTANCE IN CENTIMETERES IS \n";
cout<< cms;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to change the values of integers of second array according to first array.
#include <iostream>
using namespace std ;
int main ( )
{
int A [ 5 ] , B [ 5 ] ;
for ( int i = 0 ; i < 5 ; i++ )
{
cout << " Enter a number in 1st loop : " << endl ;
cin >> A [ i ] ;
}
for ( int i = 0 ; i < 5 ; i++ )
{
cout << " Enter a number in Second loop : " << endl ;
cin >> B [ i ] ;
}
B [ 0 ] = A [ 0 ];
for ( int i = 0 ; i < 5 ; i++ )
{
B [ 0 ] = A [ i ] + B [ i - 1 ];
cout << B [ 5 ];
}
return 0 ;
}
using namespace std ;
int main ( )
{
int A [ 5 ] , B [ 5 ] ;
for ( int i = 0 ; i < 5 ; i++ )
{
cout << " Enter a number in 1st loop : " << endl ;
cin >> A [ i ] ;
}
for ( int i = 0 ; i < 5 ; i++ )
{
cout << " Enter a number in Second loop : " << endl ;
cin >> B [ i ] ;
}
B [ 0 ] = A [ 0 ];
for ( int i = 0 ; i < 5 ; i++ )
{
B [ 0 ] = A [ i ] + B [ i - 1 ];
cout << B [ 5 ];
}
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to calculate the table of given number .
#include <iostream>
using namespace std;
int main ( )
{
int a ;
cout <<" Enter a number ";
cin >> a ;
cout << a << "*1=" << a*1 << endl ;
cout << a << "*2=" << a*2 << endl ;
cout << a << "*3=" << a*3 << endl ;
cout << a << "*4=" << a*4 << endl ;
cout << a << "*5=" << a*5 << endl ;
cout << a << "*6=" << a*6 << endl ;
cout << a << "*7=" << a*7 << endl ;
cout << a << "*8=" << a*8 << endl ;
cout << a << "*9=" << a*9 << endl ;
cout << a << "*10=" << a*10 << endl ;
return 0 ;
}
using namespace std;
int main ( )
{
int a ;
cout <<" Enter a number ";
cin >> a ;
cout << a << "*1=" << a*1 << endl ;
cout << a << "*2=" << a*2 << endl ;
cout << a << "*3=" << a*3 << endl ;
cout << a << "*4=" << a*4 << endl ;
cout << a << "*5=" << a*5 << endl ;
cout << a << "*6=" << a*6 << endl ;
cout << a << "*7=" << a*7 << endl ;
cout << a << "*8=" << a*8 << endl ;
cout << a << "*9=" << a*9 << endl ;
cout << a << "*10=" << a*10 << endl ;
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to calculate the sum of two numbers
#include <iostream>
using namespace std ;
int main ( )
{
int a , b , sum ;
cout <<" Enter the first number \n ";
cin >> a ;
cout <<" Enter the second number \n ";
cin >> b ;
sum = a + b ;
cout <<" Sum = " << sum ;
return 0 ;
}
using namespace std ;
int main ( )
{
int a , b , sum ;
cout <<" Enter the first number \n ";
cin >> a ;
cout <<" Enter the second number \n ";
cin >> b ;
sum = a + b ;
cout <<" Sum = " << sum ;
return 0 ;
}
C++ program to calculate how many numbers are positive or negative in given numbers (second method)
#include <iostream>
using namespace std;
int main()
{
int n[10];
int pos,neg;
pos=neg=0;
for ( int i = 0 ; i<6 ; i++ )
{
cout << "Enter integer to check" << endl ;
cin >> n [i];
if (n[i]>0)
{
pos++;
}
else
{
neg++;
}
}
cout << "+ve numbers are" << endl << pos ;
cout << "\n -ve numbers are" << endl << neg;
return 0 ;
}
using namespace std;
int main()
{
int n[10];
int pos,neg;
pos=neg=0;
for ( int i = 0 ; i<6 ; i++ )
{
cout << "Enter integer to check" << endl ;
cin >> n [i];
if (n[i]>0)
{
pos++;
}
else
{
neg++;
}
}
cout << "+ve numbers are" << endl << pos ;
cout << "\n -ve numbers are" << endl << neg;
return 0 ;
}
Labels:
C++ codes,
C++ programs,
Learn C++
C++ program to calculate how many numbers are positive or negative in given numbers
#include<iostream>
using namespace std;
int main()
{
int target , p=0, n=0, num;
cout << "Enter how many numbers you wants to enter? " ;
cin >> target;
for( int i = 1 ; i <= target ; i++ )
{
cout << "Enter a number : " ;
cin >> num ;
if (num>0) p++ ;
if (num<0) n++ ;
}
cout << "Positive numbers = " << p;
cout << "\n Negative numbeers =" << n;
return 0;
}
using namespace std;
int main()
{
int target , p=0, n=0, num;
cout << "Enter how many numbers you wants to enter? " ;
cin >> target;
for( int i = 1 ; i <= target ; i++ )
{
cout << "Enter a number : " ;
cin >> num ;
if (num>0) p++ ;
if (num<0) n++ ;
}
cout << "Positive numbers = " << p;
cout << "\n Negative numbeers =" << n;
return 0;
}
Labels:
C++ codes,
C++ programs,
Learn C++
Friday, April 3, 2015
C++ program to calculate electric bill
#include <iostream>
using namespace std;
int main ()
{
int a,b;
cout<<" DESIGNED BY : MUHAMMAD REHAN ASGHAR" <<endl;
cout<<" ELECTRICITY BILL CALCULATOR" <<endl;
cout<<" ENTER YOUR UNITS \n";
cin>> a;
if (a<=100)
{
b=a*3;
cout<<" YOUR BILL IS \n";
cout<< b;
}
else if (a<=300)
{
b=(100*3)+(a-100)*7;
cout<<" YOUR BILL IS \n";
cout<< b;
}
else if (a>300)
{
b=(100*3)+(200*7)+(a-300)*11;
cout<<" YOUR BILL WILL BE\n";
cout<< b;
}
return 0;
}
using namespace std;
int main ()
{
int a,b;
cout<<" DESIGNED BY : MUHAMMAD REHAN ASGHAR" <<endl;
cout<<" ELECTRICITY BILL CALCULATOR" <<endl;
cout<<" ENTER YOUR UNITS \n";
cin>> a;
if (a<=100)
{
b=a*3;
cout<<" YOUR BILL IS \n";
cout<< b;
}
else if (a<=300)
{
b=(100*3)+(a-100)*7;
cout<<" YOUR BILL IS \n";
cout<< b;
}
else if (a>300)
{
b=(100*3)+(200*7)+(a-300)*11;
cout<<" YOUR BILL WILL BE\n";
cout<< b;
}
return 0;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs,
Learn C++
C++ program to calculate either the number is palindrome or not
#include <iostream>
using namespace std ;
int main ( )
{
int n , rev = 0 ;
cout <<" Enter the number ";
cin >> n ;
for ( int n1 = n ; n1 > 0 ; n1 = n1 / 10 )
{
rev = rev * 10 + n1 % 10 ;
}
cout << rev ;
if ( rev == n )
{
cout <<" \n The number is a palindrome ";
}
else
{
cout <<" \n The number is not pelindrome ";
}
return 0 ;
}
using namespace std ;
int main ( )
{
int n , rev = 0 ;
cout <<" Enter the number ";
cin >> n ;
for ( int n1 = n ; n1 > 0 ; n1 = n1 / 10 )
{
rev = rev * 10 + n1 % 10 ;
}
cout << rev ;
if ( rev == n )
{
cout <<" \n The number is a palindrome ";
}
else
{
cout <<" \n The number is not pelindrome ";
}
return 0 ;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs,
Learn C++
C++ program to calculate BMI
#include<iostream>
using namespace std;
int main()
{
float w, h, bmi;
cout<<"Enter Weight In Kg\n";
cin>>w;
cout<<"Enter height In Meters\n";
cin>>h;
bmi=w/(h*h);
cout<<bmi;
if (bmi<18.5)
cout<<"\n underweight";
if (bmi>18.5 && bmi<20.9)
cout<<"\n normal";
if (bmi>21.0 && bmi<23.9)
cout<<"\n obese";
return 0;
}
using namespace std;
int main()
{
float w, h, bmi;
cout<<"Enter Weight In Kg\n";
cin>>w;
cout<<"Enter height In Meters\n";
cin>>h;
bmi=w/(h*h);
cout<<bmi;
if (bmi<18.5)
cout<<"\n underweight";
if (bmi>18.5 && bmi<20.9)
cout<<"\n normal";
if (bmi>21.0 && bmi<23.9)
cout<<"\n obese";
return 0;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs,
Learn C++
C++ program to calculate area of rectangle
#include<conio.h>
#include<iostream>
#include<unistd.h>
using namespace std;
int main ()
{
int i;
for(i=0;i<=100;i++)
{
cout<<"Loading......."<<i<<"%\r";
usleep(100000);
}
cout<<" DESIGNED BY:\n";
cout<<" MUHAMMAD REHAN ASGHAR\n";
int a;
int b;
cout<<"ENTER THE LENGHT\n";
cin>> a;
cout<<"ENTER THE WIDTH\n";
cin>> b;
int y;
y=a*b;
cout<<"AREA IS =\n";
cout<< y;
return 0;
}
#include<iostream>
#include<unistd.h>
using namespace std;
int main ()
{
int i;
for(i=0;i<=100;i++)
{
cout<<"Loading......."<<i<<"%\r";
usleep(100000);
}
cout<<" DESIGNED BY:\n";
cout<<" MUHAMMAD REHAN ASGHAR\n";
int a;
int b;
cout<<"ENTER THE LENGHT\n";
cin>> a;
cout<<"ENTER THE WIDTH\n";
cin>> b;
int y;
y=a*b;
cout<<"AREA IS =\n";
cout<< y;
return 0;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs,
Learn C++
C++ program to add 1 in every digit of a number
#include <conio.h>
#include <iostream>
using namespace std;
int main ( )
{
int number, result;
cout<<" Program to +1 in every digit of a five digits number \n\n";
cout<<" Enter a five digits number \n";
cin>> number;
result = number + 11111;
cout<<" Number after addition will be \n";
cout<< result;
return 0;
}
#include <iostream>
using namespace std;
int main ( )
{
int number, result;
cout<<" Program to +1 in every digit of a five digits number \n\n";
cout<<" Enter a five digits number \n";
cin>> number;
result = number + 11111;
cout<<" Number after addition will be \n";
cout<< result;
return 0;
}
Labels:
C++ Calculator Program,
C++ codes,
C++ programs,
Learn C++
C++ program of simple calculator
#include <iostream>
using namespace std;
int main ( )
{
int a,b;
char c;
cout<<" ENTER THE FIRST NUMBER\n ";
cin>> a;
cout<<" ENTER THE SECOND NUMBER \n";
cin>> b;
cout<<" ENTER THE CHARACTER\n";
cin>> c;
if (c== '+')
{
cout<<" ADDITION OF TWO NUMBERS IS \n";
cout<< a+b;
}
else if (c=='-')
{
cout<<" SUBTRACTION OF TWO NUMBERS IS \n";
cout<< a-b;
}
else if (c=='*')
{
cout<<" MULTIPLICATION OF TWO NUMBERS IS \n";
cout<< a*b;
}
else if (c=='/')
{
cout<<" DIVISION OF TWO NUMBERS IS \n";
cout<< a/b;
}
else
{
cout<<" INVALID CHARACTER \n";
}
return 0;
}
using namespace std;
int main ( )
{
int a,b;
char c;
cout<<" ENTER THE FIRST NUMBER\n ";
cin>> a;
cout<<" ENTER THE SECOND NUMBER \n";
cin>> b;
cout<<" ENTER THE CHARACTER\n";
cin>> c;
if (c== '+')
{
cout<<" ADDITION OF TWO NUMBERS IS \n";
cout<< a+b;
}
else if (c=='-')
{
cout<<" SUBTRACTION OF TWO NUMBERS IS \n";
cout<< a-b;
}
else if (c=='*')
{
cout<<" MULTIPLICATION OF TWO NUMBERS IS \n";
cout<< a*b;
}
else if (c=='/')
{
cout<<" DIVISION OF TWO NUMBERS IS \n";
cout<< a/b;
}
else
{
cout<<" INVALID CHARACTER \n";
}
return 0;
}
Labels:
C++ Calculator Program,
C++ programs
Subscribe to:
Posts (Atom)