Write ac program that reads two integers and checks whether they are multiplied or not

#include <stdio.h> int main() { double a, b, product; printf("Enter two numbers: "); scanf("%lf %lf", &a, &b); // Calculating product product = a * b; // %.2lf displays number up to 2 decimal point printf("Product = %.2lf", product); return 0; }

Output

Enter two numbers: 2.4 1.12 Product = 2.69

In this program, the user is asked to enter two numbers which are stored in variables a and b respectively.

printf("Enter two numbers: "); scanf("%lf %lf", &a, &b);

Then, the product of a and b is evaluated and the result is stored in product.

product = a * b;

Finally, product is displayed on the screen using printf().

printf("Product = %.2lf", product);

Notice that, the result is rounded off to the second decimal place using %.2lf conversion character.

I'm new to programming and I'm trying to write a C program with two integer variables a and b. When the user types in these two variables, it should tell me if b is a multiple of a. Here's what I've done so far..

int main(void) /* standard header in c programming */ { int a; int b; printf("first number : \n"); scanf("%d", &a); printf("second number : \n"); scanf("%d", &b); }

I don't really know, if I should use "if..else" and what my algorithm should look like? Any help will be much appreciated. Thanks !

8

This is a C program to accept two integers and check if they are equal.

This program accepts two integers and check if they are equal or not.

1. Take the two integers as input. 2. Using if,else statements check if they are equal or not.

3. Print the output accordingly and exit.

Here is source code of the C program to accepts two integers and check if they are equal. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C program to accept two integers and check if they are equal
  3.  */
  4. #include <stdio.h>
  5. void main()
  6. {
  7. int m, n;
  8.  
  9. printf("Enter the values for M and N\n");
  10. scanf("%d %d", &m, &n);
  11. if (m == n)
  12. printf("M and N are equal\n");
  13. else
  14. printf("M and N are not equal\n");
  15. }

1. Take the two integers as input and store it in the variables m and n respectively. 2. Using if,else statements check if m is equal to n. 3. If they are equal, then print the output as “M and N are equal”.

4. Otherwise print it as “M and N are not equal”.

Subscribe Now: C Programs Newsletter | Important Subjects Newsletters

Case:1 Enter the values for M and N 3 3 M and N are equal   Case:2 Enter the values for M and N 5 8 M and N are not equal

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

Participate in C Programming Certification Contest of the Month Now!

Next Steps:

  • Get Free Certificate of Merit in C Programming
  • Participate in C Programming Certification Contest
  • Become a Top Ranker in C Programming
  • Take C Programming Tests
  • Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.

1).The values of a and b are: 5 15 Not multiplied 2)The values of a and b are:15 5 Multiplied

Last update on May 27 2022 12:21:48 (UTC/GMT +8 hours)

Write a C program that takes two integers and test whether they are multiplies are not.

In science, a multiple is the product of any quantity and an integer. In other words, for the quantities a and b, we say that b is a multiple of a if b = na for some integer n, which is called the multiplier. If a is not zero, this is equivalent to saying that b/a is an integer.

Sample Solution:

C Code:

#include <stdio.h> int main () { unsigned short int x, y, multi; printf("Input two integers: \n"); scanf("%hd %hd", &x, &y); if (x > y){ multi = x%y; if ( multi == 0){ printf("Multiplies\n"); } else{ printf("Not Multiplies\n"); } } else{ multi = y%x; if (multi == 0){ printf("Multiplies\n"); } else{ printf("Not Multiplies\n"); } } }

Sample Output:

Input two integers: 3 9 Multiplies

Flowchart:


C programming Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C program that reads three integers and sort the numbers in ascending order. Print the original numbers and sorted numbers.
Next: Write a C program that read the item’s price and create new item price and increased price of that item according to the item price table.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Why doesn't the compiler report a missing semicolon?

C is a free-form language. That means you could format it in many ways and it will still be a legal program.

a = b * c;

could be written like

a=b*c;

or like

a = b * c ;

So when the compiler see the lines:

temp = *a *a = *b; it thinks it means temp = *a * a = *b;

Ref : //bit.ly/3fO0uGw

Postingan terbaru

LIHAT SEMUA