Computer Programming Lab Programs I Sem 2018-19
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;
printf("\n Result of the above expression is=%d",r);
r=4*8/2+8;
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:
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:
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:
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