Program Ms C Programming
Program Ms C Programming
Program Ms C Programming
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\n I am The Modern Institute of Engneering &
Technology \n");
printf("\n Badal Deb Memorial Educational Foundation
\n");
printf("\n Kailashnagar(G.T.Road) P.O.-Bandel,Dist-
Hooghly,PIN-712123,W.B. \n");
printf("\n*********Good Bye**********");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\n This is a new line\n");
printf("\b This is a back space\n");
printf("\t This is a horizontal tab\n");
printf("\v This is a vertical tab\n");
printf("\\ This is a backslash\n");
printf("\? This is a question mark\n");
printf("\o This is a null\n");
printf("\a This is a audible alert(bell)\n");
printf("\n ********This Good bye********");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,sum;
clrscr();
printf("\nEnter the value of a,b and c");
scanf("%d%d%d",&a,&b,&c);
sum=(a+b+c);
printf("\nThe Addition is: %d",sum);
getch();
}
//Avarage of giving three number//
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,avg;
clrscr();
printf("\nEnter the value of a,b and c");
scanf("%f%f%f",&a,&b,&c);
avg=(a+b+c)/3;
printf("\nThe Avarage is: %f",avg);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,x,sum=0;
float avg;
clrscr();
printf("\n How many number is want to enter :");
scanf("%d",&n);
for(i=1;i<=n;i++)
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("\nFind a number even or not\n\n");
printf("\nEnter a number to test\n\n");
scanf("%d",&n);
if(n%2==0)
printf("\n%d is an even number",n);
else
printf("\n %d ia anodd number",n);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,max;
clrscr();
printf("Enter the values of two numbers::");
scanf("%d%d",&a,&b);
max=a;
if(b>max)
max=b; // Statement-set
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the values of two numbers::");
scanf("%d%d",&a,&b);
printf("\n\n First Number =%d \n Second Number =%d",a,b);
if(a>b)
printf("\nFirst Number %d is larger ",a );
else
printf("\nSecond Number %d is larger ",b );
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nEnter the value of a,b and c : \n ");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if( a>c)
printf("\n The Largest number is a: %d",a);
}
else
{
if(b>c)
printf("\n next largest one is b : %d",b);
else
printf("\n The smallest number is c :%d",c);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z,a,b;
printf(" Enter three numberss");
scanf("%d%d%d",&x,&y,&z);
a= (x>y)?x:y;
b= (a>z)?a:z;
printf(" Largest number is %d",b);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("\nEnter the value of n, where n<1000, not greater then 1000\n ");
scanf("%d",&n);
if(n>=100)
{
printf("\n The number is 3 digit:");
}
else
if(n>=10)
{
printf("\n The number is 2 digit:");
}
else
printf("\n The number single digit:");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,digit,sum=0;
clrscr();
printf("\nEnter the value of n \n ");
scanf("%d",&n);
while(n!=0)
{
digit=n%10;
sum=sum+digit;
n=n/10;
}
printf("\n The sum of entered digit is: %d",sum);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("\nEnter the value of n \n ");
scanf("%d",&n);
if(n<0)
{
printf("\n The entered number is negative: %d",n);
}
else
{
printf("\n The enterted number is positive :%d",n);
}
printf("\n The program is over.........");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
i=0;
do
{
i=i++;
printf("\t%d\t",i);
}
while(i<100);
printf("\n The task is over");
getch();
}
//Area of a Cercular//
#include<stdio.h>
#include<conio.h>
#define PIE 3.1415
void main()
{
float r,area,perimeter;
clrscr();
printf("\nEnter the value of r \n ");
scanf("%f",&r);
area=PIE*r*r;
perimeter=2.0*PIE*r;
printf("\nArea of a cercular is: %f",area);
printf("\n perimeter of a cercular is: %f",perimeter);
getch();
}
//Area,perimeter and digonal length of rectangular//
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,area,perimeter;
float x,dl;
clrscr();
printf("\nEnter the value of a and b: \n ");
scanf("%d%d",&a,&b);
area=(a*b);
perimeter=2*(a+b);
x=(a*a+b*b);
dl=sqrt(x);
printf("\nArea of a rectagular is: %d",area);
printf("\n perimeter of a rectagular is: %d",perimeter);
printf("\nDigonal Length of a rectagular is: %f",dl);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,s;
float ar;
clrscr();
printf("\nEnter three sides of the triangle:\n");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
ar=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nThe area is :\n%f",ar);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float f,c;
clrscr();
printf("\n For Celsius to fahrenheit press 1.\n ");
printf("\n For Fahrenheit to celcius press 2.\n ");
scanf("%d",&x);
switch(x)
{
case 1:
printf("\n Enter the value of celsius: \n");
scanf("%f",&c);
f=(1.8*c)+32.0;
printf("\nThe fahrenheit temperature is:%f",f);
break;
case 2:
printf("\n Enter the value of Fahrenheit: \n");
scanf("%f",&f);
c=0.555555*(f-32.0);
printf("\nThe celsius temperature is: %f",c);
break;
default:
printf("\n Your choice is Unknown");
break;
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int y;
clrscr();
printf("\nEnter the year : \n ");
scanf("%d",&y);
if(y%100==0)
{
if( y%400==0)
printf("\n The year is leap year %d",y);
else
printf("\n The year is not leap year %d",y);
}
else
{
if(y%4==0)
printf("\n The year is leap year %d",y);
else
printf("\n The year is not leap year %d",y);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int yr;
clrscr();
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%7==0)
{
continue;
}
printf("%d",i);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0,n;
clrscr();
printf("enter number");
scanf("%d",&n);
for(i=1;i<=n-1;i++)
{
if(n%i==0)
{
sum=sum+i;
}
}
if(sum==n)
printf("perfect");
else
printf("not perfect");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,x;
clrscr();
printf("\nTo check the root of a given Equation\n ");
scanf("%f%f%f",&a,&b,&c);
x=(b*b-4*a*c);
if(x>0)
printf("\nRoot are Uneqal & Real");
else
{
if(x==0)
printf("\n Root are equal & real");
else
printf("\n Root aren Imaginary");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,flag;
clrscr();
printf("enter number");
scanf("%d",&n);
flag=0;
for(i=2;i<=n/2;i++)
if(n%i==0)
{
flag=1;
}
if(flag==0)
printf("the no is prime");
else
printf("the no is not prime");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i=2,n,f=0;
clrscr();
printf("\nEnter the number of n: \n ");
scanf("%d",&n);
while(i<=n-1)
{
if(n%i==0)
{
f=1;
break;
}
i=i+1;;
}
if(f==1)
printf("\n The number is not prime :%d",n);
else
printf("\nThe number is prime :%d",n);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,num,r,rev;
clrscr();
printf("\nEnter the number\n");
scanf("%d",&n);
num=n;rev=0;
while(n>0)
{
r=n%10;
rev=(rev*10)+r;
n=n/10;
}
if(rev==num)
printf("\nThe number is a palindrome\n");
else
printf("\nThe number is not a palindrome\n");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,a,p;
clrscr();
printf("\nEnter the number of n: \n ");
scanf("%d",&n);
r=0;
a=n;
while(n!=0)
{
p=n%10;
r=r*10+p;
n=n/10;
}
if(a==r)
printf("\n The number is Palindrome");
else
printf("\nThe number is not Palindrome");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m,x,sum;
clrscr();
printf("\nEnter the number\n");
scanf("%d",&n);
sum=0;
m=n;
while(n>0)
{
x=n%10;
sum=sum+(x*x*x);
n=n/10;
}
if(m==sum)
printf("\nArmstrong number\n");
else
printf("\n Not an armstrong number\n");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
Int i,x,sum=1,k=0,num,n;
clrscr();
printf("Enter a Number");
scanf("%d",&n);
num=n;
while(num>0)
{
x=num%10;
sum=1;
for(i=x;i>=1;i--)
{
sum=sum*i;
}
k=k+sum;
num=num/10;
}
if(n==k)
printf("%d is a Krishnamurthy Number",n);
else
printf("%d is not a Krishnamurthy Number ", n);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,flag=0;
clrscr();
printf("Enter any number");
scanf("%d",&n);
while(n>1)
{
if(n%2!=0)
{
flag=1;
break;
}
n=n/2;
}
if(flag==1)
{
printf("The no. is not power of 2");
}
else
printf("The no. is power of 2");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter two number a and b: ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\n a=%d \n b=%d ",a,b);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nEnter two number a and b: ");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("\n a=%d \n b=%d ",a,b);
getch();
}
Program-7.10: Program to check whether a given alphabet is vowel or
not
#include <stdio.h>
#include <conio.h>
Void main()
{
char ch;
printf("Enter the letter: ");
ch=getchar();
switch(ch)
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' :
printf("\n %c is a vowel ",ch);
break;
default:
printf("\n %c is a consonant",ch);
}
}
//s=1+2+3+4+5+..............+n. sum=(n(n+1))/2 //
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("\nEnter the value of n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum=(sum+i);
printf("\nThe Addition is: %d",sum);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
printf("Enter the value of n: ");
scanf("%d",&n);
i=1;
while(i<=n)
{
sum =(i+sum);
i++ ;
}
printf("Sum of first %d natural numbers is %d\n", n,sum);
getch();
}
//s=2+4+6+8+10.........+n //
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("\nTo print the sum of giving even number ");
printf("\nEnter the value of n ");
scanf("%d",&n);
for(i=2;i<=n;i=i+2)
{
sum=(sum+i);
}
printf("\nThe Addition is giving even number: %d",sum);
getch();
}
//s=1+3+5+7+9+11.........+n //
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("\nTo print the sum of giving odd number ");
printf("\nEnter the value of n ");
scanf("%d",&n);
for(i=1;i<=n;i=i+2)
{
sum=(sum+i);
}
printf("\nThe Addition is giving odd number: %d",sum);
getch();
}
//S=1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)+...........//
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
float sum=0.0,term=1.0;
clrscr();
printf("\nEnter the number of n: \n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
term=(-1)*term*(2*i-3)/(2*i-1);
sum=sum+term;
}
printf("\n The total sum is: %f",sum);
getch();
}
//S=1+(1/3)+(1/5)+(1/7)+(1/9)+(1/11)+...........//
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
float sum=1.0,term=0.0;
clrscr();
printf("\nEnter the number of n: \n ");
scanf("%d",&n);
for(i=1;i<n;i++)
{
term=1.0/(i+2);
sum=sum+term;
}
printf("\n The total sum is: %f",sum);
getch();
}
//s=1-3+5-7+9-11.........+n //
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n,sum=0,term=0;
clrscr();
printf("\nEnter the value of n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
term=(2*i-1)*pow(-1,i+1);
sum=(sum+term);
}
printf("\nThe Addition is : %d",sum);
getch();
}
//s=1-4+7-10+13-16.........+n //
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n,sum=0,term=0;
clrscr();
printf("\nEnter the value of n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
term=(3*i-2)*pow(-1,i+1);
sum=(sum+term);
}
printf("\nThe Addition is : %d",sum);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,d,sum,avg;
clrscr();
printf("\nEnter the 4 marks : \n ");
scanf("%f%f%f%f",&a,&b,&c,&d);
sum=(a+b+c+d);
avg=sum/4;
printf("\n Sum=%f",sum);
printf("\n Avarage=%f",avg);
if(avg>=80)
{
printf("\n The grade is A");
}
else
if(avg>=75&&avg<80)
{
printf("\nThe grade is B");
}
else
if(avg>=70&&avg<75)
{
printf("\nThe grade is C");
}
else
if(avg>=65&&avg<70)
{
printf("\nThe grade is D");
}
else
if(avg<65)
{
printf("\n There is no gread");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
float P,R,T,SI;
clrscr();
printf("Enter principle amount,P = ");
scanf("%f",&P);
printf("Enter rate of interest/annum,R = ");
scanf("%f",&R);
printf("Enter time period,T = ");
scanf("%f",&T);
SI=(P*R*T)/100;
printf("The amount of Simple Interest is = ");
printf("%f",SI);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
float basic,da,hra,gross;
clrscr();
printf("enter the value of Basic salary");
scanf("%f",&basic);
da=0.74*basic;/*multiplication operator is used for DA */
hra=0.15*basic; /*multiplication operator isused for HRA */
gross=basic+da+hra; /*addition is used to for Gross salary*/
printf("The Gross Salary is= %f",gross);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int num,r;
clrscr();
printf(" Enter a number");
scanf("%d",&num);
r=(num>0)?(num):(-num);
printf("The absolute value of %d is %d",num,r);
getch();
}
/*
Output:
Enter a number 9
The absolute value of 9 is 9
Enter a number -9
The absolute value of -9 is 9 */
#include<stdio.h>
#include<conio.h>
void main ()
{
int i,j,row;
clrscr();
printf("Enter the number of rows");
scanf("%d",&row);
for(i=1;i<=row;i++) // for-1(outer) used to control row
{
for(j=1;j<=i;j++) // for-2(inner) used
{
printf("*"); // to print ‘*’
}
printf ("\n");
}
}
/* OUTPUT:
Enter the number of rows 5
*
* *
* * *
* * * *
* * * * *
*/
//Write a program to ptint like this//
/*
**
***
****
*****
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,row;
clrscr();
printf("Enter the number of rows");
scanf("%d",&row);
for(i=1;i<=row;i++) // for-1(outer) used to control row
{
for(j=1;j<=(row-i);j++)
printf(" "); // to print blank space
for(j =1;j<=i;j++) // for-2(inner) used
printf("*"); // to print ‘*’
printf ("\n");
}
}
/*
OUTPUT:
Enter the number of rows 5
*
**
***
****
*****
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,row;
clrscr();
printf("enter row:");
scanf("%d",&row);
for(i=1;i<=row;i++) // line-1
{
for(j=1;j<=(row-i);j++) // line-2
printf(" "); // line-3
for(k=1;k<=i;k++) // line-4
printf("* "); // line-5
printf("\n"); // line-6
}
getch();
}
/* OUTPUT:
enter row 4
*
* *
* * *
* * * *
*/
/*
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5 */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,p;
clrscr();
printf("Enter Number of rows ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\t");
for(j=1;j<=(n-i);j++)
printf(" ");
p=i;
for(j=1;j<2*i;j++)
{
printf("%3d",p);
if(j>=i)
p--;
else
p++;
}
printf("\n\n");
}
getch();
}