general c programs
TRANSCRIPT
-
7/25/2019 General C Programs
1/27
Program 1Write a C program to swap two numbers without using athird variable
#include
int main()
int a! b"
print($%n&nter value or num1 ' num $)"
scan($*d *d$! 'a! 'b)"
a + a , b"
b + a - b"
a + a - b"
print($%n ter swapping value o a *d$! a)"
print($%n ter swapping value o b *d$! b)"
return (/)"
0
&nter value or num1 'num 1/ /ter swapping value o a /ter swapping value o b 1/
-
7/25/2019 General C Programs
2/27
Program Program to convert temperature rom degree
centigrade to ahrenheit
#include
int main()
2oat celsius! ahrenheit"print($%n&nter temp in Celsius $)"
scan($*$! 'celsius)"
ahrenheit + (1.3 4 celsius) , 5"print($%n6emperature in ahrenheit * $!
ahrenheit)"
return (/)"
0
&nter temp in Celsius 56emperature in ahrenheit 37.87773
-
7/25/2019 General C Programs
3/27
Program 5 Program to calculate actorial o a number using
or loop
#include
int main()
int i!+1!num"
print($&nter a number $)"
scan($*d$!'num)"
or(i+1"i
-
7/25/2019 General C Programs
4/27
Program : Program to calculate actorial o a number using recursive unction
#include
int fact(int);int main()
{
int factorial, num;
printf("Enter the value of num :");
scanf("d", !num);factorial fact(num);
printf("actorial is d", factorial);
return ($);
%
int fact(int n){ if (n $)
{
return (&);
%
return (n ' fact(n &));%
-
7/25/2019 General C Programs
5/27
Program 8 C Program to reverse a given number
#include
int main()
int num! rem! rev + /"
print($%n&nter an; no to be reversed $)"
scan($*d$! 'num)" while (num >+ 1)
rem + num * 1/"
rev + rev 4 1/ , rem" num + num 1/"
0
print($%n=eversed umber *d$! rev)"
return (/)"
0
&nter an; no to bereversed 15=eversed umber 51
-
7/25/2019 General C Programs
6/27
Program ? n electric power distribution compan; charges
its domestic consumers as ollows-
Consumption Charge =ate o @nits
------------------------------------------------------
/-// =s./.8/ per unit
/1-:// =s.1// plus =s./.?8 per uniteAcess //
:/1-?// =s.5/ plus =s./.3/ per unit
eAcess o ://. -------------------------------------------------------
Write a C program that reads the customernumber and power consumed and prints theamount to be paid b; the customer.
-
7/25/2019 General C Programs
7/27
#include
void main()
int custBno! power@sage"
2oat amount" print($&nter the customer number $)" scan($*d$!
'custBno)"
print($&nter the power consumed $)" scan($*d$!
'power@sage)"i (power@sage >+ / '' power@sage :// '' power@sage
-
7/25/2019 General C Programs
8/27
Program ? - Program to Chec Whether Diven umber is Perect Er ot
#include
int main()
int num! i + 1! sum + /"
print($&nter a number $)"
scan($*d$! 'num)"
while (i < num)
i (num * i ++ /) sum + sum , i" 0
i,,"
0
i (sum ++ num) print($*d is a Perect umber$! i)"
else
print($*d is on Perect umber$! i)"
return /" 0
-
7/25/2019 General C Programs
9/27
Program F - Program to Chec Whether Diven umber is rmstrong Erot
#include
int main()
int num! temp! sum + /! rem"
print($%n&nter number or checing rmstrong $)"
scan($*d$! 'num)"
temp + num" while (num G+ /)
rem + num * 1/"
sum + sum , (rem 4 rem 4 rem)"
num + num 1/" 0i (temp ++ sum) print($*d is mstrong umber$!temp)"
else print($*d is mstrong umber$!
temp)"
-
7/25/2019 General C Programs
10/27
-
7/25/2019 General C Programs
11/27
-
7/25/2019 General C Programs
12/27
-
7/25/2019 General C Programs
13/27
-
7/25/2019 General C Programs
14/27
-
7/25/2019 General C Programs
15/27
-
7/25/2019 General C Programs
16/27
-
7/25/2019 General C Programs
17/27
-
7/25/2019 General C Programs
18/27
-
7/25/2019 General C Programs
19/27
-
7/25/2019 General C Programs
20/27
-
7/25/2019 General C Programs
21/27
-
7/25/2019 General C Programs
22/27
-
7/25/2019 General C Programs
23/27
-
7/25/2019 General C Programs
24/27
-
7/25/2019 General C Programs
25/27
-
7/25/2019 General C Programs
26/27
-
7/25/2019 General C Programs
27/27