C Assignment
C Assignment
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:-
}
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:-
void main()
{
int n, r, i, factn=1, factr=1, factnr=1, ncr, npr;
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;
switch(option)
{
case 1: printf("enter the length and breadth");
scanf("%d%d",&len,&bre);
result = len*bre;
printf("%d",result);
break;
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;
}
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);
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;
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':
break;
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:-