0% found this document useful (0 votes)
31 views

PR Ogr Ams:: 1.Pr I Nthel L Owor L D

The document contains 10 C programming examples: 1) a program to print hello world, 2) a program to perform basic arithmetic operations, and 3) other programs to convert temperatures, swap numbers, find ASCII values, calculate factorials, check for leap years, solve quadratic equations, calculate sums of GP series, generate Fibonacci series, and check for Armstrong numbers.

Uploaded by

sanjay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

PR Ogr Ams:: 1.Pr I Nthel L Owor L D

The document contains 10 C programming examples: 1) a program to print hello world, 2) a program to perform basic arithmetic operations, and 3) other programs to convert temperatures, swap numbers, find ASCII values, calculate factorials, check for leap years, solve quadratic equations, calculate sums of GP series, generate Fibonacci series, and check for Armstrong numbers.

Uploaded by

sanjay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Pr

ogr
ams:

1.Pr
inthel
l
owor
ld:

#i
ncl
ude<st
dio.
h>

i
nt
mai n()
{
printf(
"\t
Doy ouwanttoprinthel
l
owor
ld!(
Y/N)
\n\
t")
;
chardes;
scanf("%c",&des);
i
f( des=='Y')
print
f("\t
Hell
oWor l
d!"
);
else
print
f("\t
Asy ourwi
sh")
;
return0;
}

2.Addsubdi
vmul
ti2nos:

#i
ncl
ude<st
dio.
h>

i
ntmai n()
{
pri
ntf("\tWhi charit
hmeticoperat
iony
ouwanttodo");
pri
ntf("\n\t1.addit
ion,2.
subst
racti
on,
3.mul
ti
pli
cat
ion,4.
div
isi
on:
\n\
t")
;
pri
ntf("
Ent ery ourchoi
ce:"
);
i
ntdes;
fl
oatnum1, num2;
scanf("%d" ,
&des) ;
pri
ntf("\tEnteranumber :"
);
scanf("%f ",
&num1) ;
pri
ntf("
\tEnteranot hernumber:
");
scanf("
%f ",&num2) ;
i
f(des==1)
{f
loatadd;
add=num1+num2;
pri
ntf("\tans:%f",
add);
}
el
sei f(des==2)
{f
loatsub;
sub=num1- num2;
pri
ntf("\t
ans:%f"
,sub);
}
elseif(des==3)
{fl
oatmt n;
mt n=num1* num2;
pri
ntf("
\tans:%f
",
mt n)
;}
elseif(des==4)
{fl
oatdiv;
div=num1/ num2;
pri
ntf("
\tans:%f
",
div);
}
retur
n0;
}

2.Degr
eef
ahr
enhi
te:

#i
ncl
ude<st di
o.h>
i
ntmain()
{
fl
oattemp_ c,
temp_ f
;
pri
ntf("
Entertemperatur
eindegreecel
cius:
")
;
scanf("%f
",&t
emp_ c)
;
temp_f=((
9.0/5.
0)*t
emp_ c)
+32;
pri
ntf("
Temper at
ureindegreef
ahrenhi
te:%f"
,t
emp_
f);
}

3.swapnumber
s:

#i
ncl
ude<st dio.
h>
i
ntmain()
{
i
ntx,y;
pri
ntf("
\tEnteranumbertosaveinvari
ablex:"
);
scanf("%d",
&x);
pri
ntf(
"\tEnt
eranunmbert osavei
nv ari
abley:
")
;
scanf("%d",
&y);
pri
ntf("
\tSwappinginprogr
ess.
..
\n")
;
x=x+y;
y=x-
y;
x=x-
y;
pri
ntf("
\tSwappingdone\n")
;
pri
ntf("
\tval
uestoredinvari
abl
ex:%d\n",
x);
pri
ntf("
\tval
uestoredinvari
abl
ey:%d",
y);
ret
urn0;
}

4.Asci
ival
ues:
#i
ncl
ude<stdio.h>
i
ntmain()
{
i
ntcharacter;
pri
ntf("
\tEnteracharact
ert
ofindit
'sASCIIval
ue:
");
scanf(
"%c",&charact
er)
;
pri
ntf("
\tASCIIvalueof%c:%d",
charact
er,
char
acter)
;
ret
urn0;

5.Fact
ori
al:
#i
ncl
ude<stdio.h>
i
ntmain()
{
i
ntnum, f
act=1,i
;
pri
ntf("
Enteranumbertofi
ndfactor
ial
:"
);
scanf("
%d" ,
&num);
for(
i=1;
i<=num;i=i
+1)
f
act=fact*
i;
pri
ntf("
Factori
alof%d:%d"
,num,f
act);
ret
urn0;

6.l
eapy
ear
#i
ncl
ude<st
dio.
h>

i
ntmai n()
{
i
nty ear;
printf("
Enteryear
:"
);
scanf (
"%d",
&year)
;
i
f( year%4==0)
pr
intf(
"%disaleapyear
.",
year
);
else
pr
intf(
"%disnotaleapyear.
",
year
);
return0;
}

7.quadr
ati
cequat
ion:
#i
ncl
ude<st
dio.
h>
#i
ncl
ude<math.
h>

i
ntmain()
{
fl
oata,b,c,det,
root1,root2;
pri
ntf("Entercoef f
icientofx2: ");
scanf("%f ",
&a);
pri
ntf("
Ent ercoeffi
ci entofx: ")
;
scanf("%f ",
&b);
pri
ntf("Entertheconst antt erm:")
;
scanf("
%f ",
&c);
det=pow( b,2)-
(4*a*c) ;
root1=(-
b+pow( det,0.5)
)/(2* a)
;
root2=(-
b-pow( det,0.5))/
(2* a);
pri
ntf("
Root soft hegi venf unctionar
e%fand%f
",
root
1,r
oot
2);
return0;
}

8.Sum ofgp:
#i
ncl
ude<st
dio.
h>
#i
ncl
ude<math.
h>
#i
ncl
ude<st
dli
b.h>

i
ntmain()
{
fl
oata,r
,n,
sum;
pri
ntf("
Entert
hef i
rstt
erm ofG.P:
");
scanf("
%f",
&a);
pri
ntf("
Entert
hecommondi ff
erenceofG.P:
")
;
scanf("
%f",
&r);
pri
ntf("
Entert
henumberoft ermsinG.P:"
);
scanf("
%f",
&n);
sum=abs((a*(
1-pow(r,
n))
)/(
1-r
));
pri
ntf("
Sum ofGivenG.P: %f"
,sum);
ret
urn0;
}
9.Foi
bonacci
ser
ies:
#i
ncl
ude<st
dio.
h>

i
ntmain()
{
i
nta=0,b=1, sum, n,
i;
pri
ntf("
Ent ernumberoft er
ms(
>2)
:"
);
scanf("
%d" ,
&n) ;
i
ntarray[n] ;
array
[0]=0;
array
[1]=1;
i
f(n>2)
sum=a+b;
for
(i=3; i<=n;
i=i+1)
{a=b;
b=sum;
sum=a+b;
array [
i-
1]=b;}
for(i
=0;i<=n- 1;i
=i+1)
pri
nt f("%d" ,array
[i
])
;

r
etur
n0;
}

10.Ar
mst
rong
#i
ncl
ude<st dio.h>
#i
ncl
ude<mat h.h>
i
ntmain()
{
i
ntnum, n,sum=0, r
1,i
,
q,r
,d;
pri
ntf("Enternumberofdi gi
ts:
");
scanf("
%d" ,
&n) ;
pri
ntf("
Enternumbert ocheckf orar
mst
rong:
")
;
scanf("
%d" ,
&num) ;
r1=num;
for(
i=n;
i>=1;i=i
-1)
{
if(
i>1)
{
q=r 1/(
pow(10,(
i-
1))
);
d=pow( 10,(
i-
1));
r=r1%d;
r1=r ;
sum=sum+pow(q,3);
}
el
seif(
i=1)
sum=sum+pow(r1,3)
;
}
i
f( sum==num)
pr
int
f("
%dnumberisar mstr
ong",
num);
else
pr
int
f("
%dnumberisnotar mst
rong"
,num)
;
return0;
}

You might also like