Category Archives: c++ programming examples

Explore a diverse range of practical C++ programming examples

C++ Program to Read an Amount and Find Number of Notes

C++ program to count all notes in a certain quantity – In this unique essay, we’ll go over the many C++programming techniques for counting all the notes in a certain quantity.

The following are the methods used in C++ programming to determine how many notes overall there are in a given quantity:

  • Using the Standard Procedure
  • Making Use of User-Defined Function
  • Employing Pointers

As we all know, with cash bundles, a number of notes combine to equal the exact quantity of money that the person in question needs.

Similar to that, this blog discusses the various methods for counting the number of notes in a certain amount. In a bundle, a single note’s multiples are multiplied.

The total number of notes in a particular quantity can be counted using a C++ program. Check out the whole code with example programs and sample outputs here. You can check out more introductory C++ programs here.

Thus, there are a number of ways to calculate notes in a given quantity in C++ programming, as follows:

C++ Program to Read an Amount and Find Number of Notes

Logic to count minimum number of denomination for given amount

There are numerous efficient algorithms available to address the given issue. To simplify things for this experiment, I utilized the greedy method.

Using descriptive logic, determine the least amount of denominations.

Amount entered by the user. Put it in a variable, like amt.
If the amount is higher than 500, divide it by 500 to get the maximum number of notes needed, which is 500. Put the result of the division in a variable, such as note500 = amt / 500;.
Divide the original sum by 500 notes, and then deduct the result. Execute note500 * 500 – amt.

For each note, repeat the previous step 200, 100, 50, 20, 10, 5, 2, and 1.

#include<iostream>

using namespace std;

class money{

public:

    int note_size[9]={1000,500,200,100,50,20,10,5,2};

    int note_count[9]={0};

     money(int amount){

        for (int i=0;i<9;i++){

            if(amount>=note_size[i]){

                note_count[i]=amount/note_size[i];

                amount=amount%note_size[i];

            }

        }

        cout<<"counted notes >>"<<endl;

        for (int i=0;i<9;i++){

            if(note_count[i]!=0){ cout<<note_size[i]<<" taka x"<<note_count[i]<<endl;

            }   }                 }  };

int main(){   int amount;

cout<<"enter total amount : "; //C++ Program to Read an Amount and Find Number of Notes

cin >>amount;

money ob(amount);

return 0;}

Output:

C++ Program to Read an Amount and Find Number of Notes

Understanding Conditional Statements in C Programming, If Else in C

Nested if else in C Programming Examples1

Nested if else in c programming examples

#include <stdio.h>
int main()
{ int s;
    printf ("enter your score =");
    scanf("%d",&s);

    if(s>=80 && s<=100){
        printf("A+");
    }
else if(s>=75 && s<=79){



printf("A= 3.75");
}

else if(s>=70 && s<=74){

printf("A-=3.50");
}
else if(s>=65&&s<=69){

    printf("B+=3.25");

}
else if(s>=60 && s<=64){

  printf("B=3.00");
}
else if(s>=55 && s<=59){

    printf("B-=2.75");
}
else if(s>=50 && s<=54){

     printf("c+=2.5");
 }
else if(s>=45&&s<=49){
    printf("c=2.25");
}
else if(s>=40&&s<=44){

    printf("D=2.0");
}
else{
    printf("Failed? ");
    printf("         000000        \n");
    printf("     ((^^^^^^^^^^))      \n ");
    printf("    (( ^^   ^^  ))     \n");
    printf("     ((  0    0  ))    \n");
    printf("     ((    00    ))    \n");
    printf("      (( <||||> ))     \n");
    printf("        ((____))       \n");



}
}

Understanding Conditional Statements in C || C programming examples

See more

Factorial Program in C || What is the factorial of 100 in C

Sieve of Eratosthenes C++ code

Sieve of Eratosthenes C++ code

sieve of eratosthenes c++ code

For the first time, I have developed a C++ application that compiles and runs flawlessly. I’ve made the decision to learn C++, and in order to become comfortable with the language, I’ve developed my first C++ program, which I wrote all by myself after only a few hours of instruction. (Also, no “Hello, World.” program has been written by me.

Example:1

#include<iostream> using namespace std; void primeSieve(int n) { int prime[100]={0}; for(int i=2;i<=n;i++) { if(prime[i]==0){ for(int j=i*i;j<=n;j+=i){ prime[i]==1; } } } for(int i=2;i<=n;i++) { if(prime[i]==0) { cout<<i<<" ";

  }cout<<endl;
}

} int main() { int a; cin>>a; primeSieve(a); }

see more

C++ Program to Read an Amount and Find Number of Notes