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

C_Lab_A

Uploaded by

mraj43621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

C_Lab_A

Uploaded by

mraj43621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Q1. C PROGRAM TO FIND LARGEST OF 3 NUMBERS ?

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,large;
clrscr();
printf("Enter 3 numbers");
scanf("%d %d %d",&a,&b,&c);
large=a;
if(b>large)
large=b;
if(c>large)
large=c;
printf("Large number is %d",large);
getch();
}

OUTPUT:

Q2. C PROGRAM TO DISPLAY N FIBONACCI SERIES ?

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=0,fib1=0,fib2=1,fib3;
clrscr();
printf("Enter the limit\n");
scanf("%d",&n);
printf("Fibonacci numbers are\n");
while(i<n)
{
if(i==0)
printf("%d\n",fib1);
else if(i==1)
{
printf("%d\n",fib2);
}
else
{
fib3=fib1+fib2;
fib1=fib2;
fib2=fib3;
printf("%d\n",fib3);
}
i++;
}
getch();
}

OUTPUT:

Q3. C PROGRAM TO FIND THE TAX RATE FOR THE GROSS SALARY OF ANY EMPLOY BASED ON THE
GIVEN CONDITION ?

GROSS <2000 NO TAX

GROSS >=2000 AND <4000 3% TAX

GROSS >=4000 AND <6000 5% TAX

GROSS >6000 8% TAX

#include<stdio.h>
#include<conio.h>
void main()
{
long int gross;
int tax=0,index;
clrscr();
printf("Enter the gross salary:");
scanf("%ld",&gross);
index=gross/1000;
switch(index)
{
case 0:
case 1:tax=0;
break;
case 2:
case 3:tax=gross*3/100;
break;
case 4:
case 5:tax=gross*5/100;
break;
default:tax=gross*8/100;
break;
}
printf("Gross pay=%ld\n Tax=%d",gross,tax);
getch();
}

OUTPUT:

Q4. C PROGRAM TO REVERSE A NUMBER AND FIND THE SUM OF INDIVIDUAL DIGITS. ALSO CHECK
FOR PALINDROME ?

#include<stdio.h>
#include<conio.h>
void main()
{
int rem=0,rev=0,sum=0,num,org;
clrscr();
printf("Enter the number");
scanf("%d",&num);
org=num;
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
sum=sum+rem;
}
printf("The reverse of %d is %d\n",org,rev);
if(org==rev)
printf("%d is a palindrome",org);
else
printf("%d is not palindrome",org);
printf("\n Sum of %d is %d",org,sum);
getch();
}

OUTPUT:
Q5. C PROGRAM TO FIND GCD OF TWO NUMBERS. ALSO FIND THE LCM?

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,x,y,t,gcd,lcm;
clrscr();
printf("Enter two integers\n");
scanf("%d %d",&x,&y);
a=x;
b=y;
while(b!=0)
{
t=b;
b=a%b;
a=t;
}
gcd=a;
lcm=(x*y)/gcd;
printf("Greatest common divisor of %d and %d is % d\n",x,y,gcd);
printf("Least common multiple of %d and %d is %d",x,y,lcm);
getch();
}

OUTPUT:

Q6. C PROGRAM TO CHECK WHETHER GIVEN NUMBNER IS PRIME OR NOT?

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,c=0;
clrscr();
printf("Enter a number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
{
printf("%d is a prime number",n);
}
else
{
printf("%d is not prime number",n);
}
getch();
}

OUTPUT:

Q7. C PROGRAM TO CONVERT A DECIMAL NUMBER TO BINARY EQUIVALENT?

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i;
clrscr();
printf("Enter decimal number to convert");
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%2;
n=n/2;
}
printf("\nBinary equivalent to given number is ");
for(i=i-1;i>=0;i--)
{
printf("%d",a[i]);
}
getch();
}
OUTPUT:

You might also like