Skip to main content

Posts

Showing posts from January, 2017

finding value of a character as integer in c++

#include<iostream> using namespace std; int main() { int x = 0x63; float y = 32.245; char z = 'c'; cout<< "x is " << x << " y is " << y << " z is " <<  z << '\n'; z = x; x = y; y = z; cout<< "x is " << x << " y is " << y << " z is " <<  z << '\n'; x = 0x5632; //how many bytes are needed for 0x5632? z = x; cout<< "x is " << x << '\n'; cout<< "z as a character is " << hex << z << "....and as integer..." <<  (int) z; return 0; } output x is 99 y is 32.245 z is c x is 32 y is 99 z is c x is 22o66 z as a character is 2....and as integer...32

operator values program in c++

#include<iostream> using namespace std; int main() { int i=0; int j=1; int k=5; bool btype = true; bool btype2 = false; cout<<i<<'\t'<<j<<'\t'<<k<<'\t'<<btype<<'\t'<<btype2<<'\t'<<endl; btype = 100<7 && !(5>10) || !btype2 && (j==0); cout<<i<<'\t'<<j<<'\t'<<k<<'\t'<<btype<<'\t'<<btype2<<'\t'<<endl; btype = 11>5 && (j=9) || (i=4); cout<<i<<'\t'<<j<<'\t'<<k<<'\t'<<btype<<'\t'<<btype2<<'\t'<<endl; btype = 10<4 || (i=1) && (j=7); cout<<i<<'\t'<<j<<'\t'<<k<<'\t'<<btype<<'\t'<<btype2<<'\t'<<endl; b...

base 10 to octal conversion of multiple numbers in c++ using for loop

#include<iomanip> #include<iostream> using namespace std; int main() { int x; for(int i=0;i<5;i++) {  cout<<"Please enter input:";  cin>>x; cout<<"Your input in base 10 is "<<x<<" and in base 8 is "<<oct<<x<<endl; } return 0; } *************************** output:

convert multiple numbers from base 10 to base 16 in c++ using for loop

#include<iomanip> #include<iostream> using namespace std; int main() { int x; for(int i=0;i<5;i++) {  cout<<"Please enter input:";  cin>>x; cout<<"Your input in base 10 is "<<x<<" and in base 16 is "<<hex<<x<<endl; } return 0; } ************************************ output:

Checking number of digits in C++ using if else conditions

#include<iostream> using namespace std; int main() { int x=0; int i; int y; int z; int a; int d; int c; int b; cout<<"enter a four digit number:"; cin>>x; a=x%10; y=x/10; b=y%10; z=y/10; c=z%10; d=z/10; if(d>9) { cout<<"number is not 4 digit"; } else if(d==0) { cout<<"number is not 4 digit"; } else { cout<<d<<endl; cout<<c<<endl; cout<<b<<endl; cout<<a<<endl; } return 0; } ************************ output:

a program in c++ to check either a number is a Armstrong or Not using while loop and if condition

#include<iostream> using namespace std; int main() { int x=0; int sum=0; int y; int a; int b; cout<<"enter a number:"; cin>>x; b=x; while(x>0) { a=x%10; y=a*a*a; x=x/10; sum+=y; } if(sum==b) { cout<<"The Number is Armstrong"; } else { cout<<"The Number is Not Armstrong"; } return 0; } ***************************************** output:

Using for loop Print a plus sign in c++

#include<iostream> using namespace std; int main () { for(int i=0; i<4; i++) { cout<<"     "<<"*"<<endl; } for(int j=0; j<6; j++) {     cout<<"*"<<" "; } cout<<endl; for(int i=0; i<4; i++) {     cout<<"     "<<"*"<<endl; } } ****************************88 output:

Do while loop program in c++

#include<iostream> using namespace std; void clearscreen(); main() { int x = 1; int y = 10; do { cout<<x; cout<<'\n'; x++; } while( x < y ); } ************************* Output:

Taking cube of numbers using function in C++

#include <iostream> int Cube ( int ) ; // prototype using namespace std; int main () {    int      x;    int      y ;     x   = 14 ;     y   =   9 ;    cout <<"My Number ="  << y ;    cout <<"and its cube is:"  << Cube (y) << endl ;    cout <<"Your Number ="  << x ;    cout <<"and its cube is:"  << Cube (x) << endl ;    return 0; } int Cube ( int n) {     int a;     a = n*n*n;     return a; } ************************************* output:

Combination Program using functions in c++

#include<iostream> using namespace std; int main () { int x, y, z, m, n, r; int o; int fac(int n); cout<<"number of man:"; cin>>n; x= fac(n); cout<<"number of thing:";     cin>>r; y= fac(r); z= n-r;     o = fac(z);     m = o*y;     n = x/m;     cout<<"total possible combination among them:"<<n;     return 0; } int fac(int n) {     int a=1;     for(int i=1; i<=n; i++)     { a= a*i;     } return a; } ************************************************* output:

Weight conversion program using functions in c++

#include<iostream> using namespace std; int num(int n) { cout<<"num of chocolate:"; cin>>n; return n; } int ounce(int a) { cout<<"weight in ounce:"; cin>>a; return a; } int pound(int b) { cout<<"weight in pound:"; cin>>b; return b; } int main () { int n, a, b; char choice; cout<<"enter choice 'o' for ounce and 'p' for pounds:"; cin>>choice; int x, y, z; x = num(n); y = ounce(a); z = pound(b); if (choice == 'o') {cout<<"total weight in ounce:"<<x*y;} if (choice == 'p') {cout<<"total weight in pounds:"<<x*z;} return 0; } ************************** Output:

Sum of numbers using function in c++

#include<iostream> using namespace std; void ud(int Number1,int Number2) { int k; k =Number1+Number2;     cout<<k; }  main() {     int x,y;     cout<<"enter no 1:";     cin>>x;     cout<<"enter no 2:";     cin>>y;     cout<<"sum of numbers is: ";     ud(x, y); } **************************************** output:

Swapping number program in c++

#include<iostream> using namespace std; main() { int x,y;     cout<<"enter no 1:";     cin>>x;     cout<<"enter no 2:";     cin>>y; cout<<x<<y; cout<<endl; swap(x,y); cout<<"Number after swaping: "; cout << x << y; } ************************************************* Output:

comparison of two values in c++

 #include <iostream> using namespace std; int max(int num1, int num2) {     int result;    if (num1 > num2)       {result = num1;}    else       {result = num2;}       result= result-7;    return result; } int min (int num1,int num2 ) {     int result;     if(num1<num2)         {result = num1;}     else        {result =num2;}        result= result+5;     return result; } int sum(int num1,int num2) {  int c, d, sum;  c = max(num1, num2);    d=min (num1, num2);    sum=c+d;    return sum; } int main () {    int a;    cin>>a;    int b;    cin>>b;    int  p;    p = sum(a, b);  if(p>10)    cout << "First entered val...

How to Print a running Fan in C++ using functions

#include<iostream> using namespace std; void fun() { cout<<"            *    "<<endl; cout<<"            *    "<<endl; cout<<"          *****  "<<endl; cout<<"            *    "<<endl; cout<<"            *    "<<endl; system cls(); } void fun2() { cout<<"          *   *"<<endl; cout<<"           * * "<<endl; cout<<"            *  "<<endl; cout<<"           * * "<<endl; cout<<"          *   *"<<endl; system cls(); } main() { while(1) { fun(); for (int i = 0; i < 100000000; i++) { } fun2(); for ...

How to sum numbers in c

#include<stdio.h> int main() {     int x, y;     printf("enter value of x:");     scanf("%d",&x);     printf("enter value of y:");     scanf("%d",&y);     printf("sum of x and y is= %d", x+y);     getch();     return 0; } *********************************************

Simple program in c for beginner

#include<stdio.h> int main() {     printf("i am a boy");     return 0; }

Bubble sort program by using pointers and functions in c

#include<stdio.h> void swap(int *x, int *y) { int temp; temp= *x; *x=*y; *y=temp; } int main() { int size,m,n; printf("Enter size of array:"); scanf("%d",&size); int a[size]; for(m=0;m<size;m++) { printf("Enter values of %d array element:",m); scanf("%d",&a[m]); } for(m=0;m<size;m++) { for(n=m+1;n<size;n++) { if(a[m]>a[n]) { swap(&a[m],&a[n]); } } } for(m=0;m<size;m++) { printf("%d\t",a[m]); } getch(); return 0; }

How to sum two 2D arrays

#include<stdio.h> int main() { int m,n,o,r,c; printf("Enter the number of rows of arrys:"); scanf("%d",&r); printf("Enter the number of colums of arrys:"); scanf("%d",&c); int a[r][c]; int b[r][c]; printf("\nEnter values of first 2d arrays:\n"); for(m=0;m<r;m++) {    for(n=0;n<c;n++)   { printf("Enter values of array element for %d row and %d coulm:",m,n);   scanf("%d",&a[m][n]);   } } printf("\nEnter values for 2nd arry element\n"); for(m=0;m<r;m++) {    for(n=0;n<c;n++)     {   printf("Enter values of array element for %d row and %d coulm:",m,n);     scanf("%d",&b[m][n]);   } } printf("\n"); printf("First aaray elements are\n"); for(m=0;m<r;m++) {     for(n=0;n<c;n++)    {   printf("%3d",a[m][n]);    }   printf("\n"); } printf("Second aaray elements...