/* C program to swap two numbers without using temporary variables */
main()
{
printf("\n enter any two values");
scanf("%d%d",&a,&b);
printf("\n Before swapping a=%d\tb=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\n After swapping a=%d\tb=%d",a,b);
}
OUTPUT:
enter any two values 5 10
Before swapping a=5 b=10
After swapping a=10 b=5
/* C program to find the roots of the quadratic equation */
main()
{
int a,b,c,r1,r2,d;
clrscr();
printf("\n enter the coefficients of a quadratic equation");
scanf("%d%d%d",&a,&b,&c);
d=b*b-(4*a*c);
if(d==0)
{
r1=-b/(2*a);
r2=-b/(2*a);
printf("roots are equal %d and %d",r1,r2);
}
if(d>0)
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("roots are real %d and %d",r1,r2);
}
if(d<0)
{
printf("\n roots are imaginary");
}
}
OUTPUT:
enter the coefficients of a quadratic equation
1 -2 1
roots are equal 1 1
/* C program to find the biggest of three numbers using ternary operator */
main()
{
int a=7775,b=12,c=225,x;
x=a>b?(a>c?a:c):(b>c?b:c);
printf("biggest number is %d",x);
}
OUPUT:
biggest number is 7775
/* C program to find the sum of digits of a given number */
main()
{
int n,r,sum=0,n1;
printf("\n enter any number");
scanf("%d",&n);
n1=n;
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("\n sum of digits of %d is %d",n1,sum);
OUTPUT:
enter any number
132
sum of digits of 132 is 6
/* C program to check whether the given number is palindrome or not */
main()
{
int n,r,sum=0,n1;
printf("\n enter any number");
scanf("%d",&n);
n1=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(sum==n1)
printf("%d is palidrome number",n1);
else
printf("%d is not palindrome number",n1);
}
OUTPUT:
enter any number
121
121 is a palindrome number
/* C program to check whether the given number is armstrong or not */
main()
{
int n,r,sum=0,n1;
printf("\n enter any number");
scanf("%d",&n);
n1=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(sum==n1)
printf("%d is armstrong number",n1);
else
printf("%d is not armstrong",n1);
}
OUTPUT:
enter any number
153
153 is armstrong
/* C program to check whether the given number is prime number or not */
main()
{
int n,c=0,i;
printf("enter a number");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
c=1;
break;
}
}
if(c==0)
printf("%d is prime number",n);
else
printf("\n %d is not prime number",n);
}
OUTPUT:
enter a number 34
34 is not prime number
/* C program to print multiplication tables up to the given range */
main()
{
int n,i,j;
printf("\n enter your range");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=10;j++)
{
printf("\n %d * %d = %d",i,j,i*j);
}
printf("\n ");
}
}
OUTPUT:
enter your range 10
/* C program to print Fibonacci Sequence with in the given range */
main()
{
int n,a=0,b=1,c;
printf("enter your range");
scanf("%d",&n);
printf("\n %d \t %d",a,b);
c=a+b;
while(c<=n)
{
printf("\t%d",c);
a=b;
b=c;
c=a+b;
}
}
OUTPUT:
enter your range 25
0 1 1 2 3 5 8 13 21
C lab sample program, c lab manual c lab r16 lab manual , c lab sample programs , c lab R16, palindrome, armstrong, prime number or not, call by value, fibonacci sequence, multiplication tables
No comments:
Post a Comment