Computer Programming Lab Programs Regulation15
PRIORITY &
ASSOCIATIVITY OF OPERATORS USING EXPRESSIONS
AIM:
The main
aim this programs is
To write a C program to understand the
priority and associativity of operators using expressions.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void
main()
{
int r;
clrscr();
r=2+3*8;
// Since multipliation is having
higher priority than addition ,
// multiplication is performed first
and then addition
printf("\n Result of the above
expression is=%d",r);
r=4*8/2+8;
//Both multiplication and division
has equal priority and
// hence by using associativity rule
, multiplication is performed
//first and then division as the
rule is from left to right
printf("\n Result of the above
expression is=%d",r);
}
INPUT & OUTPUT:
RESULT:
DIFFERENT
LIBRARY FUCNCTIONS IN C
AIM:
The main aim this programs is
to Write a C program to use different library functions of C language
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
void
main()
{
int n;
float f;
char name[20];
clrscr();
printf("\n Enter a
number:");
scanf("%d",&n);
f=sqrt(n);
printf("\n Square root of
number=%6.4f",f);
printf("\n Ceil value of above
result= %f",ceil(f));
printf("\n Floor value of above
result= %f",floor(f));
flushall();
printf("\n Enter a name
:");
scanf("%s",name);
printf("\n Length of the
name=%d",strlen(name));
printf("\n Given name in
uppercase= %s",strupr(name));
printf("\n Given name in lowercase=
%s",strlwr(name));
printf(" \n Reverse of the
name= %s",strrev(name));
}
INPUT & OUTPUT:
RESULT:
ROOTS OF A QUADRATIC EQUATION
AIM:
The main aim this programs is To write a C
program to find
the roots of a quadratic equation.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void
main()
{
int a,b,c,d;
float r1,r2;
clrscr();
printf(" \n Enter
the values of a,b,c in a quadratic
equation : "); scanf("%d%d%d",&a,&b,&c);
if(a==0)
{
printf("\n The
equation is linear");
r1=(float)-c/b;
printf("\n Linear root of the equation is=%f",r1);
}
else
{
d=(b*b)-(4*a*c);
if(d==0)
{
printf("\n The roots are real and equal");
r1=(float)(-b/(2*a));
printf(" Common root is =%f",r1);
}
else if (d>0)
{
printf("\n The
roots are real and distinct");
r1=(float)(-b+sqrt(d)/(2*a));
r2=(float)(-b-sqrt(d)/(2*a));
printf("\n One
root = %f",r1);
printf("\n Another
root is=%f",r2);
}
else
{
printf(" The
roots are imaginary");
}
}
}
INPUT & OUTPUT:
RESULT:
FACTORIAL
OF A GIVEN NUMBER
AIM:
The main aim this programs is to write a program to find the factorial of a given number.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int
n,f=1,i=1;
clrscr();
printf("\n
Enter a number:");
scanf("%d",&n);
while(i<=n)
{
f*=i;
i++;
}
printf("Factorial
of %d is = %d",n,f);
getch();
}
INPUT & OUTPUT:
RESULT:
PRIME
NUMBER CHECKING
AIM:
The main aim this programs is
to write a C program to check whether the number is prime or not.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void
main( )
{
int n,i,k=0;
clrscr();
printf("\n Enter a number
:");
scanf("%d",&n);
i=1;
while(i<=n)
{
if(n%i==0)
k++;
i++;
}
if(k==2)
printf("\n Given
number %d is a prime number",n);
else
printf("\n Given
number %d is not a prime number",n);
}
INPUT & OUTPUT:
RESULT:
GENERATE
SERIES OF PRIME NUMBERS
AIM:
The main aim this programs is to write a C
program to generate all the prime numbers between 1 and n .
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int
n,i,j,k=0;
clrscr();
printf("Enter
n value upto where prime numbers to be found: ");
scanf("%d",&n);
if(n==0)
{
printf("
\n Invalid number entered");
}
printf("
\n Required prime numbers are :");
for(i=2;i<=n;i++)
{
k=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
k++;
}
if(k==2)
printf("\t%d",i);
}
getch();
}
INPUT & OUTPUT:
RESULT:
FIBONACCI
SERIES
AIM:
The main aim this programs is to
write a C program to generate the Fibonacci numbers in the given range.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void
main()
{
int
n,i,f1=0,f2=1,f;
clrscr();
printf(" \n Enter
how many fibonacci numbers you want
to print : ");
scanf("%d",&n);
printf("\n Fibonacci
series is :\n");
printf("%d\t%d",f1,f2);
for(i=3;i<=n;i++)
{
f=f1+f2;
printf("\t%d",f);
f1=f2;
f2=f;
}
getch();
}
INPUT & OUTPUT:
RESULT:
MAXIMUM
& MINIMUM OF SET OF NUMBERS
AIM:
The main aim this programs is to write a C program to find maximum and minimum of set of numbers.
#include<conio.h>
PROGRAM:
#include<stdio.h>
void main()
{
int
a[20],i,min,max,n;
clrscr();
printf("\n
Enter no. of elements:");
scanf("%d",&n);
printf("\n
Enter the elements :");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
min=max=a[1];
for(i=2;i<=n;i++)
{
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
printf("\n
Given elements are:\n");
for(i=1;i<=n;i++)
printf("%5d",a[i]);
printf("\n
Maximum Value is=%d",max);
printf("\n
Minimum Value is=%d",min);
getch();
}
INPUT & OUTPUT:
RESULT:
REVERSE
THE DIGITS OFA NUMBER
AIM:
The main aim this programs is
to write a C program to reverse the digits of a number.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void
main()
{
int n,rem,rev=0;
clrscr();
printf("\n Enter a number
:");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
printf("\n The reverse of given
number is:%d",rev);
getch()
}
INPUT & OUTPUT:
RESULT:
SUM
OF POSITIVE & NEGATIVE NUMBERS IN A GIVEN SET
AIM:
The main aim this programs is to write a program to find the sum of positive
and negative numbers in a given set of numbers.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void
main()
{
int a[20],n,sp=0,sn=0,i;
clrscr();
printf("\n Enter size of the
array :");
scanf("%d",&n);
printf("\n Enter the values of
array :");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
if(a[i]<0) //
negative
sn=sn+a[i];
else // positive
sp=sp+a[i];
}
printf("\n In given numbers,sum
of positive values is :%d",sp);
printf("\n In given numbers,sum
of negative values is :%d",sn);
}
INPUT & OUTPUT:
RESULT:
NUMBER
PALINDROME
AIM:
The main aim this programs is
to write a C program to check for number palindrome.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void
main( )
{
int n,rem,rev=0,temp;
clrscr();
printf("\n Enter a number:");
scanf("%d",&n);
temp=n;
while(temp>0)
{
rem=temp%10;
rev=rev*10+rem;
temp=temp/10;
}
if(n==rev)
printf("\n Given
number %d is Palindrome",n);
else
printf("\n Given
number %d is not a palindrome",n);
}
INPUT & OUTPUT:
RESULT:
SUM
OF SERIES
AIM:
The main aim this programs is to write a program to evaluate the sum of the
given series
= 1+x+
/2!+
/3!+
/4!+----




PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void
main()
{
float sum=1.0;
int n,x,i,fact=1;
clrscr();
printf("\n enter x and n
values:");
printf("\n x=");
scanf("%d",&x);
printf("\n n=");
scanf("%d",&n);
for(i=1;i<n;i++)
{
fact=fact*i;
sum=sum+(float)pow(x,i)/fact;
}
printf("\n sum of the given
series is %f",sum);
getch();
}
INPUT & OUTPUT:
RESULT:
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home