Sunday, 6 June 2021

C++ Program to input a decimal number and print in Binary, Octal, and Hexadecimal form with inbuilt function itoa

 C++ Program to input a decimal number and print in Binary, Octal, and Hexadecimal form with inbuilt function itoa




 

This function is not defined in ANSI-C and is not part of C++, but is supported by some compilers.



 

#include <iostream>
#include <stdlib.h>
#include<iomanip>
using namespace std;
int main ()
{
  int i;
  char buffer [20];
  cout<<"Enter The Number : ";
  cin>>i;
  cout<<"------------------------------------------------------------"<<endl;
  itoa (i,buffer,10);
  cout<<setw(15)<<"Decimal : "<<buffer<<endl;
  itoa (i,buffer,16);
  cout<<setw(15)<<"Hexadicimal : "<<buffer<<endl;
  itoa (i,buffer,2);
  cout<<setw(15)<<"Binary : "<<buffer<<endl;
  itoa (i,buffer,8);
  cout<<setw(15)<<"Octal : "<<buffer<<endl;
  return 0;
}
 

Syntax of the function itoa :

char *  itoa ( int value, char * str, int base );


Output:



Share:

Friday, 4 June 2021

C++ program to calculate the sum of n complex number without class

 C++ program to calculate the sum of n complex number without class





//#include <iostream>
#include<bits/stdc++.h>

using namespace std;
int main()
{
    int numilj;
    cout << "Enter how match complex number :";
    cin >> i;
    int complex[i][2], real = 0ima = 0;

    for (l = 0l < il++)
    {

        cout << "Enter the real number :";
        cin >> complex[l][1];
        cout << "Enter the imaganary number : i";
        cin >> complex[l][2];
    }
    for (l = 0l < il++)

    {
        cout << l + 1 << " number input is :" << complex[l][1<< " + i" << complex[l][2<< endl;
    }
    for (l = 0l < il++)
    {
        real += complex[l][1];
        ima += complex[l][2];
    }
    cout << "The sum of all is = " << real << "+ i" << ima;
    return 0;
}



Output:


Share:

Friday, 28 May 2021

Create a structure Book with entities - bname,aname,page,price.Input data for 10 books .Print the detail of the book with highest page number.

Create a structure Book with entities - book name, author name, page, price.

Input data for 10 books. Print the detail of the book with the highest page number.






#include <stdio.h>
#include <conio.h>
#include <string.h>


/*Structure define*/
struct bookList
{
    char bookName[20];
    char authorName[20];
    int page;
    float price;
};

int main()
{
    int numberijmax = 0;
A1:
    printf("\nEnter Number Of Books : ");
    scanf("%d", &number);

    if (number < 2)
    {
        printf("!!!   Enter Minimum 2 Number   !!!");
        goto A1;
    }

    struct bookList book[number];
    for (i = 0i < numberi++)
    {

        printf("\nEnter  book name : ");
        scanf("%s", &book[i].bookName);
        printf("Auther Name : ");
        scanf("%s", &book[i].authorName);
        printf("Pages In The Book : ");
        scanf("%d", &book[i].page);
        printf("Price Of The Book : ");
        scanf("%f", &book[i].price);
    }

    for (i = 0i < numberi++)
    {
        if (book[i].page > book[max].page)
        {
            max = i;
        }
    }
    printf("\n%s - book has maximum number of page %d . Written by %s And the price is %.0f"book[max].bookNamebook[max].pagebook[max].authorNamebook[max].price);

    return 0;
}




Output:



Share:

Thursday, 27 May 2021

Array Data Type To Get 5 Number Input And Print Them In C Programming

Array Data Type To Get 5 Number Input And Print Them In C Programming 








#include<stdio.h> 
#include <conio.h>
int main()
{
    int num[5];
    int i;
    for (i = 0; i < 5; i++)
    {
        printf("Enter %d number data :", i + 1);
        scanf("%d", &num[i]);
    }

    for (i = 0; i < 5; i++)
    {
        printf("\nThe %d number data is: %d", i + 1, num[i]);
    }
    return 0;
}


Output:




Share:

C programming structure example with array

C programming structure example with array






#include <stdio.h>
#include <conio.h>
#include <string.h>

struct employee
{
    char name[20];
    int age;
    float salary;
};
int main()
{

    struct employee emp1, emp2, emp3;
    printf("Enter the name ,age and salary of the 3 employee\n");

    printf("1st Employee  :");
    printf("\nName:");
    scanf("%s", &emp1.name);
    printf("Age:");
    scanf("%d", &emp1.age);
    printf("Salary:");
    scanf("%f", &emp1.salary);

    printf("2nd Employee  :");
    printf("\nName:");
    scanf("%s", &emp2.name);
    printf("Age:");
    scanf("%d", &emp2.age);
    printf("Salary:");
    scanf("%f", &emp2.salary);

    printf("3rd Employee  :");
    printf("\nName:");
    scanf("%s", &emp3.name);
    printf("Age:");
    scanf("%d", &emp3.age);
    printf("Salary:");
    scanf("%f", &emp3.salary);

    printf("%s's age is %d and his salary is %.0f\n", emp1.name, emp1.age, emp1.salary);
    printf("%s's age is %d and his salary is %.0f\n", emp2.name, emp2.age, emp2.salary);
    printf("%s's age is %d and his salary is %.0f\n", emp3.name, emp3.age, emp3.salary);
    return 0;
}


Output :





Share: