0% found this document useful (0 votes)
24 views2 pages

C Programs

The document contains 4 C program examples: 1) A program to accept two integers and calculate their sum, difference, product, and quotient. 2) A program to calculate the total cost of a product given the rate per unit and quantity. 3) A program to accept time in seconds and calculate the equivalent hours, minutes, and seconds. 4) A program to calculate temperature in Celsius given temperature in Fahrenheit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

C Programs

The document contains 4 C program examples: 1) A program to accept two integers and calculate their sum, difference, product, and quotient. 2) A program to calculate the total cost of a product given the rate per unit and quantity. 3) A program to accept time in seconds and calculate the equivalent hours, minutes, and seconds. 4) A program to calculate temperature in Celsius given temperature in Fahrenheit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Write a C Program to accept two integer numbers and find their SUM, DIFF, PRODUCT, QUOTIENT

// C Program to accept two integer numbers and find their SUM, DIFF, PRODUCT, QUOTIENT
#include<stdio.h>
void main()
{
int num1, num2, sum=0, diff=0, product=0;
float quotient=0.0; OUTPUT:
clrscr(); Enter First Number
printf("Enter First Number\n"); 10
scanf("%d",&num1); Enter Second Number
printf("Enter Second Number\n"); 3
scanf("%d",&num2); Sum of 10 and 3 = 13
sum=num1+num2; Difference of 10 and 3 = 7
diff=num1-num2; Product of 10 and 3 = 30
product=num1*num2; Quotient of 10 and 3 = 3.333333
quotient=num1/num2;
printf("Sum of %d and %d = %d\n", num1, num2, sum);
printf("Difference of %d and %d = %d\n", num1, num2, diff);
printf("Product of %d and %d = %d\n", num1, num2, product);
printf("Quotient of %d and %d = %f\n", num1, num2, quotient);
getch();
}

_____________________________________________________________________________________

2. Write an algorithm and flowchart to find the total cost of a product given the rate per unit and quantity

//C Program to find the total cost of a product given the rate per unit and quantity
#include<stdio.h>
void main()
{
float rate, qty, cost=0.0; OUTPUT:
clsrscr(); Enter Quantity
printf("Enter Quantity\n",); 50
scanf("%f", &qty); Enter Rate per Unit
printf("Enter Rate per Unit\n",); 10.50
scanf("%f", &rate); Total Number of Quantity = 50.000000
cost=qty*rate; Rate per Unit = 10.500000
printf("Total Number of Quantity = %f", qty); Total Cost = 525.000000
printf("Rate per Unit = %f", rate);
printf("Total Cost = %f", cost);
getch();
}
_____________________________________________________________________________________

3. Write a C program accept the total time in seconds, find the number of Hours, Minutes and Seconds

//C program accept the total time in seconds, find the number of Hours, Minutes and Seconds
#include<stdio.h>
void main()
{
int sec, hr, min, rem; OUTPUT:
clrscr(); Enter the time in Seconds
printf("Enter the time in Seconds\n"); 3675
scanf("%d", &sec); Number of Hours= 1
min=sec/60; Number of Minutes= 1
sec=sec%60; Number of Seconds= 15
hr=min/60;
min=min%60;
printf("Number of Hours= %d\n",hr);
printf("Number of Minutes= %d\n",min);
printf("Number of Seconds= %d\n",sec);
getch();
}
4. Write a C Program to find the temperature in Celsius, given the Temperature in Fahrenheit

You might also like