Simple Computational Problems - C Programming
C Program to read two integers 'a' and 'b' and print quotient and remainder when 'a' is divided by 'b' without using the "%' operator or 'mod' function.
Suppose a=39, b=7, if 'a' is divided by 'b' quotient is '5' and remainder is 4;
Consider q=a/b, so 'q' is the quotient.
a=39, b=7, the statement q=a/b evaluates q=5
remainder = a‒q*b = 39‒5*7= 39‒35 = 4
so r=a‒q*b will calculate the remainder.
/* Program to print quotient and remainder without "%' and 'mod' function */
#include <stdio.h>
main()
{
/* Local definition */
int a,b,q,r;
/*statements */
printf("Enter a,b values.....");
scanf("%d %d", &a,&b);
q=a/b;
r=a‒q*b;
printf("Quotient is.....%d", q);
printf("Remainder is.....%d", r);
} /* main */
OUTPUT
Enter a, b values.....39 7
Quotient is.....5
Remainder is.....4
EXPLANATION: In the above program the variables a,b,q,r are declared as integer type. The scanf() function reads values of the two variables ‘a' and 'b'. 'q' is a variable holds the result of a/b and variable 'r' holds the result of (a‒q*b). After computing quotient 'q' and remainder 'r' are printed. Note that in this program the remainder is calculated without modular division.
Computer Programming C Laboratory: Basic C Programs : Tag: C Programming : - C Program to read two integers 'a' and 'b' and print quotient and remainder
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation