Programa C para Calcular Cociente y Resto

Dados dos números A y B. La tarea es escribir un programa para encontrar el cociente y el resto de estos dos números cuando A se divide por B.
 

quotient_remainder

Ejemplos
 

Input: A = 2, B = 6
Output: Quotient = 0, Remainder = 2

Input: A = 17, B = 5
Output: Quotient = 3, Remainder = 2

En el siguiente programa, para encontrar el cociente y el resto de los dos números, primero se le pide al usuario que ingrese dos números. Las entradas se escanean usando la función scanf() y se almacenan en las variables  A    B    . Luego, las variables  A    B    se dividen usando el operador aritmético  /    para obtener el cociente como resultado almacenado en la variable cociente ; y usando el operador aritmético % para obtener el resto como resultado almacenado en la variable resto
A continuación se muestran los programas para encontrar el cociente y el resto de dos números: 
 

C++

// C++ program to find quotient
// and remainder of two numbers
 
#include <iostream>
using namespace std;
 
int main()
{
  int A, B;
   
  // Ask user to enter the two numbers
  cout << "Enter two numbers A and B: ";
 
  // Read two numbers from the user || A = 17, B = 5
  cin >> A >> B;
   
  // Calculate the quotient of A and B using '/' operator
  int quotient = A / B;
   
  // Calculate the remainder of A and B using '%' operator
  int remainder = A % B;
   
  // Print the result
  cout << "Quotient when A / B is: " << quotient << endl;
  cout << "Remainder when A / B is: " << remainder;
}
 
// This code is contributed by sarajadhav12052009

C

// C program to find quotient
// and remainder of two numbers
 
#include <stdio.h>
 
int main()
{
    int A, B, quotient = 0, remainder = 0;
 
    // Ask user to enter the two numbers
    printf("Enter two numbers A and B : \n");
 
    // Read two numbers from the user || A = 17, B = 5
    scanf("%d%d", &A, &B);
 
    // Calculate the quotient of A and B using '/' operator
    quotient = A / B;
 
    // Calculate the remainder of A and B using '%' operator
    remainder = A % B;
 
    // Print the result
    printf("Quotient when A/B is: %d\n", quotient);
    printf("Remainder when A/B is: %d", remainder);
 
    return 0;
}

Java

// java program to find quotient
// and remainder of two numbers
 
 
import java.io.*;
import java.util.Scanner;
 
class GFG {
  
 
    public static void main (String[] args) {
         Scanner input = new Scanner(System.in);
    int A = input.nextInt();
    int B= input.nextInt();
    int
    quotient = 0, remainder = 0;
 
    // Ask user to enter the two numbers
    System.out.println("Enter two numbers A and B : "+" "+ A+" "+ B);
 
    // Read two numbers from the user || A = 17, B = 5
     
 
 
    // Calculate the quotient of A and B using '/' operator
    quotient = A / B;
 
    // Calculate the remainder of A and B using '%' operator
    remainder = A % B;
 
    // Print the result
    System.out.println("Quotient when A/B is: "+ quotient);
    System.out.println("Remainder when A/B is: "+ remainder);
    }
}
//this code is contributed by anuj_67..

Python3

# Python3 program to find quotient
# and remainder of two numbers
 
if __name__=='__main__':
     
    quotient = 0
    remainder = 0
 
 
#Read two numbers from the user || A = 17, B = 5
    A, B = [int(x) for x in input().split()]
 
#Calculate the quotient of A and B using '/' operator
    quotient = int(A / B)
 
#Calculate the remainder of A and B using '%' operator
    remainder = A % B
 
#Print the result
    print("Quotient when A/B is:", quotient)
    print("Remainder when A/B is:", remainder)
 
#this code is contributed by Shashank_Sharma

Salida
 

Enter two numbers A and B : 17 5
Quotient when A/B is: 3
Remainder when A/B is: 2

Publicación traducida automáticamente

Artículo escrito por RishabhPrabhu y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *