Sei sulla pagina 1di 26

Q1) Write a program to check two numbers are equal or not.

Coding:-
#include<stdio.h>
void main()
{
int n1,n2;
printf("Enter the value of n1 : ");
scanf("%d",&n1);
printf("\n Enter the value of n2 : ");
scanf("%d",&n2);
if(n1==n2)
{
printf("\nTwo numbers are equal ");
}
else
printf("\nTwo numbers not are equal ");
}
Output:-

Q2) Write a program to check given number is even or odd.


Coding:-
#include<stdio.h>
void main()
{
int n;
printf("Enter the no : ");
scanf("%d",&n);
if(n%2==0)
{
printf("\n %d is even",n);
}
else
printf("\n %d is odd ",n);
}
Output:-

Q3) Write a program to find quardrant of a given values.


Coding:-
#include<stdio.h>
void main()
{
int x,y;
printf("enter the value of x : ");
scanf("%d",&x);
printf("enter the value of y : ");
scanf("%d",&y);
if((x>=0 && y>0) || (x>0 && y>=0))
{
printf(" I Quardarent ");
}
else if((x<=0 && y>0) || (x<0 && y>=0))
{
printf(" II Quardarent ");
}
else if((x<=0 && y<0) || (x<0 && y<=0))
{
printf(" III Quardarent ");
}
else if((x>=0 && y<0) || (x>0 && y<=0))
{
printf(" IV Quardarent ");
}
else
printf("It is origin ");
}
Output:-

Q4) Write a program to find greatest of three number.


Coding:-
#include<stdio.h>
void main()
{
int a,b,c;
printf("enter A,B,C \n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("A is greater %d",a);
}
else
printf("C is greater %d",c);
}
else if(b>c)
{
printf("B is greater %d",b);
}
else
printf("C is greater %d",c);

}
Output:-
Q5) Write a program to find the grade of a subject received by the students.
Coding:-
#include<stdio.h>
void main()
{
int per;
printf("Enter the percentage value ");
scanf("%d",&per);
printf(" Grade ");
if(per>=90)
printf("O");
if(per>=75 && per<=89)
printf("E");
if(per>=60 && per<=74)
printf("A");
if(per>=50 && per<=59)
printf("B");
if(per>=40 && per<=49)
printf("C");
if(per>=33 && per<=39)
printf("Fail");
}
Output:-

Q6) Write a program to check the given letter is upper case or lower case if it is
lower case convert into upper case.
Coding:-
#include<stdio.h>
void main()
{
char n;
int v,p;
printf("Enter the Letter ");
scanf("%c",&n);
v=n;
if((v>=65) && (v<=90))
{
printf("It is in upper case ");
}
if((v>=97) && (v<=122))
{
p=v-32;
printf("Upper case is %c ",p);
}
else
printf("Not in upper case or lower case ");
Output:-

Q7) Write a program to convert upper case into lower case and lower case into
upper case. And taking in input at any input value using ternary operator.
Coding:-
#include<stdio.h>
void main()
{
char n;
int v,p;
printf("Enter the Letter ");
scanf("%c",&n);
v=n;
((v>=65) && (v<=90)) ? printf("%c",v+32):printf("");
((v>=97) && (v<=122)) ? printf("%c",v-32):printf("");
}
Output:-

Q8) Write a program to find greatest number between 3 number using ternary
operator.
Coding:-
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter the value ");
scanf("%d%d%d",&a,&b,&c);
(a>b && a>c) ? printf("%d is greatest value ",a):(b>c) ? printf("%d is greatest value ",b) : printf("%d is
greatest value ",c);
}
Output:-

Q9)Write a program to generate odd and even number upto 50.


Coding:-
#include<stdio.h>
void main()
{
int i;
printf("Even number are : ");
for(i=2;i<=50;i+=2)
{
printf("%d ",i);
}
}
Output:-

Q10) Write a program to find sum of values from 100 to 200.


Coding:-
#include<stdio.h>
void main()
{
int sum=0,n,i;
printf("Sum of numbers are : ");
for(i=100;i<=200;i++)
{
sum=sum+i;
}
printf("%d",sum);
}
Output:-

Q11) Write a program to reverse the given number


Coding:-
#include<stdio.h>
void main()
{
int n1,rev=0,temp,rem;
printf("Enter a number : ");
scanf("%d",&n1);
temp=n1;
while(n1>0)
{
rem=n1%10;
rev=rev*10+rem;
n1=n1/10;
}
printf("Reverse of %d is %d ",temp,rev);
}
Output:-

Q12)Write a program to check given number is prime or not.


Coding:-
#include<stdio.h>
void main()
{
int temp,num,i,c=0;
printf("enter a number : ");
scanf("%d",&num);
temp=num;
for(i=1;i<=num;i++)
{
if(num%i==0)
{
c++;
}
}
if(c==2)
printf("%d is a prime number ",temp);
else
printf("%d is not a prime number ",temp);
}
Output:-
Q13) Write a program to find pime number upto given range.
Coding:-
#include<stdio.h>
void main()
{
int i, prime,upper,lower, n;
printf(" ENTER THE LOWER LIMIT : ");
scanf("%d", &lower);
printf("\n ENTER THE UPPER LIMIT : ");
scanf("%d", &upper);
printf("\n PRIME NUMBERS LIST IS : ");
for(n=lower+1; n<upper; n++)
{
prime = 1;
for(i=2; i<n/2; i++)
if(n%i == 0)
{
prime = 0;
break;
}
if(prime)
printf("\t%d", n);
}
}
Output:-

Q14) Write a program to find the number is Armstrong or not.


Coding:-
#include<stdio.h>
void main()
{
int n,p,q,r,temp,r1=0,i=0;
printf("Enter the number : ");
scanf("%d",&n);
temp=n;
while(n>0)
{
p=n%10;
n=n/10;
i=i+1;
}
while(n>0)
{
q=n%10;
r=(q^i)+r1;
n=n/10;
r1=r;
}
if(r1==temp)
{
printf("%d is an armstrong number ",temp);
}
else
printf("%d is not an armstrong number ",temp);
}
Output:-

Q15) Write a program to generate fibonancci series.


Coding:-
#include<stdio.h>
void main()
{
int n,n1=0,n2=1,n3,i;
printf("enter the number : ");
scanf("%d",&n);
printf("\n%d %d ",n1,n2);
for(i=2;i<n;++i)
{
n3=n1+n2;
printf("%d ",n3);
n1=n2;
n2=n3;
}
}
Output:-

Q16)Write a program to check given year is leap year or not.


Coding:-
#include<stdio.h>
void main()
{
int yr;
printf("enter the year : ");
scanf("%d",&yr);
if((yr%4==0) && (yr%100==0) && (yr%400==0))
{
printf("%d is a leap year ",yr);
}
if(yr%4==0)
{
if(yr%100!=0)
{
printf("%d is a leap year ",yr);
}
else
printf("%d is not a leap year ",yr);
}
else
printf("%d is not a leap year ",yr);
}
Output:-
Q17) Write a program to find ncr or npr.
Coding:-
#include<stdio.h>

void main()
{
int n, r, i, factn=1, factr=1, factnr=1, ncr, npr;

printf("Enter the value of n and r:\n");


scanf("%d%d",&n,&r);

for(i=1;i<=n;i++)
{
factn = factn * i;
}

for(i=1;i<=r;i++)
{
factr = factr * i;
}

for(i=1;i<=n-r;i++)
{
factnr = factnr * i;
}

ncr = factn/(factr*factnr);
npr = factn/factnr;

printf("%dC%d = %d\n",n, r, ncr);


printf("%dP%d = %d\n",n, r, npr);
}
Output:-
Q18)Write a program to find the area of various geometric figures.
Coding:-
#include<stdio.h>
void main()
{
float rad,result;
int option, len, bre, side;
printf("choose the area you want\n");
printf("1.rectangle\n");
printf("2.square\n");
printf("3.circle\n");
scanf("%d",&option);

switch(option)
{
case 1: printf("enter the length and breadth");
scanf("%d%d",&len,&bre);
result = len*bre;
printf("%d",result);
break;

case 2: printf("enter the side");


scanf("%d",&side);
result = side*side;
printf("%d",result);
break;
case 3: printf("enter the radius");
scanf("%f",&rad);
result = 3.14*rad*rad;
printf("%f",result);
break;

default: printf("No option");


}
}
Output:-

Q19)Write a program to find the value of sinx.


Coding:-
#include<stdio.h>
void main()
{
int i, n;
float x, sum, t;
printf(" Enter the value for x : ");
scanf("%f",&x);

printf(" Enter the value for n : ");


scanf("%d",&n);

x=x*3.14159/180;
t=x;
sum=x;
for(i=1;i<=n;i++)
{
t=(t*(-1)*x*x)/(2*i*(2*i+1));
sum=sum+t;
}

printf(" The value of Sin(%f) = %.4f",x,sum);


}
Output:-

Q20) Write a program to find the value of cosx.


Coding:-
#include <stdio.h>
void main(
{
int i, j, n, fact, sign = - 1;
float x, p, sum = 0;
printf("Enter the value of x : ");
scanf("%f", &x);
printf("Enter the value of n : ");
scanf("%d", &n);
for (i = 2; i <= n; i += 2)
{
p = 1;
fact = 1;
for (j = 1; j <= i; j++)
{
p = p * x;
fact = fact * j;
}
sum += sign * p / fact;
sign = - 1 * sign;
}
printf("cos %0.2f = %f", x, 1+sum);
}
Output:-
Q21) Write a program to check the number is perfect square or not.
Coding:-
#include<stdio.h>
void main()
{
int n,s,i,p;
printf("Enter the number ");
scanf("%d",&n);
for(i=1;i<n;i++)
{
s=i*i;
if(s==n)
{
printf("%d is the perfect square ",n);
}
}
}
Output:-

Q22) Write a program to check a given number is divisible by 7 or not.


Coding:-
#include<stdio.h>
void main()
{
int num;
printf("enter the number : ");
scanf("%d",&num);
if(num%7==0)
{
printf("%d is divisible by 7 ",num);
}
else
printf("%d is not divisible by 7 ",num);
}
Output:-

Q23) Write a program to find sum of series of 1! + 2! + 3! + ………+n!.


Coding:-
#include<stdio.h>
void main()
{
int i,n,fact,sum=1;
printf("Enter the number : ");
scanf("%d",n);
for(i=1;i<n;i++)
{
fact=fact*1;
sum=sum+fact;
}
printf("sum of the series %d",sum);
}
Output:-

Q24) Write a program to find GCD and LCM of a given number.


Coding:-
#include<stdio.h>
void main()
{
int n1,n2,lcm,gcd,rem,num,den;
printf("Enter two numbers :");
scanf("%d %d",&n1,&n2);
if(n1>n2)
{
num=n1;
den=n2;
}
else
{
num=n2;
den=n1;
}
rem=num%den;
while(rem!=0)
{
num=den;
den=rem;
rem=num%den;
}
gcd=den;
lcm=n1*n2/gcd;
printf("GCD of %d and %d = %d\n",n1,n2,gcd);
printf("LCM of %d and %d = %d\n",n1,n2,lcm);
}
Output:-

Q25) Write a program to check given number is palindrome or not.


Coding:-
#include<stdio.h>
void main()
{
int n1,rev=0,temp,rem;
printf("Enter a number : ");
scanf("%d",&n1);
temp=n1;
while(n1>0)
{
rem=n1%10;
rev=rev*10+rem;
n1=n1/10;
}
if(temp==rev)
{
printf("%d is palindrome ",temp);
}
else
{
printf("%d is not palindrome ",temp);
}
}
Output:-

Q26) Write a program to check the middle number of three digit number is
either sum or product of the number.
Coding:-
#include<stdio.h>
void main()
{
int num, i, rem, sum = 0, pro = 1, temp;
printf("Enter three digit number\t");
scanf("%d",&num);
for(i=0;num!=0;i++)
{
rem = num % 10;
if(i==1)
{
temp = rem;
}
else
{
sum = sum + rem;
pro = pro * rem;
}
num = num / 10;
}
printf("Middle number = %d\nSum = %d\nProduct = %d\n",temp, sum, pro);

if(sum == temp || pro == temp)


printf("The middle number is equal to sum or the product of two numbers.");
else
printf("The middle number is not equal to sum or the product of two number.");
}
Output:-

Q27) Write a program to generate multiplication of any number.


Coding:-
#include<stdio.h>
void main()
{
int num, i, pro;
printf("Enter number\t");
scanf("%d",&num);

for(i=1;i<=10;i++)
{
pro = num * i;
printf("%d * %d = %d\n", num, i, pro);
}
}
Output:-
Q28)Write a program to find the vowels in a given text.
Coding:-
#include<stdio.h>

void main()

char sen[50];

int i, vowels=0;

printf("enter the text\n");

gets(sen);

for(i=0;i!='\n';i++)

switch(sen[i])

case 'A':

case 'a':

case 'E':

case 'e':
case 'I':

case 'i':

case 'O':

case 'o':

case 'U':

case 'u': vowels++;

break;

printf("No. of vowels: %d",vowels);

Output:-

Q29) Write a program to find prime number of the fabonaci sequence of a given
range.
Coding:-
#include <stdio.h>
void main()
{
int i, j, flag, num1=0, num2=1, res, limit;
printf("Enter the limit:- \t");
scanf("%d",&limit);
printf("\nThe prime number in the Fibbonacci series are:-\n");
for(i=0;i<limit;i++)
{
res = num1+num2;
num1=num2;
num2=res;
flag=0;

for(j=2;j<=res/2;j++)
{
if(res%j==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("%d\t",res);
}
}
}
Output:-

Q30)Write to print the pattern.


Coding:-
#include<stdio.h>
void main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=5-i;j>=0;j--)
{
printf(" *");
}
printf("\n");
}
}
Output:-

Q31)Write a program to print the pattern.


Coding:-
#include<Stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}
Output:-

Q32) Write a program to print pattern


Coding:-
#include<Stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
Output:-

Q33) Write a program to print pattern.


Coding:-
#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}
Output:-

Potrebbero piacerti anche