PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION
#include<stdio.h>

#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,flag;
float root1,root2,discr,unknown;
clrscr();
printf("PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION \n\n\n");
printf("Enter the values of a,b & c \n\n");
scanf("%d %d %d",&a,&b,&c);
printf("\n\n");
if(a==0)
{
         printf("The entered equation is not a quadratic equation \n\n");
         unknown=-c/b;
         printf("The value of the unknown is = %5.2f",unknown);
}
else
{
discr=(b*b)-(4*a*c);
if(discr<0)
flag=1;
else if(discr>0)
flag=2;
else
flag=3;
switch(flag)
{
case 1: printf("The roots are imaginary \n");
  break;
case 2: root1=(-b+sqrt(discr))/(2*a);
  root2=(-b-sqrt(discr))/(2*a);
  printf("The roots are distinct and 1st Root= %5.2f and 2nd Root= %5.2f",root1,root2);
  break;
case 3: root1=-b/(2*a);
  printf("The roots are identical and equal to %5.2f",root1);
  break;
 }
 }
getch();
}

PROGRAM TO GENERATE FIBONACCI SERIES

#include<stdio.h>

#include<conio.h>
void main()
{
int a,b,c,n,i;
clrscr();
printf("PROGRAM TO GENERATE  FIBONACCI SERIES \n\n");
printf("Enter the number of terms of fibanosies series to generate \n\n");
scanf("%d",&n);
a=1;
b=1;
i=1;
printf("\n\n");
printf("The generated Fibanosies Series is \n\n\n");
printf("%d \t %d \t",a,b);
while(i<=n-2)
{
c=a+b;
printf("%d \t",c);
a=b;
b=c;
i++;
 }
getch();
}

 PROGRAM TO CHECK PALINDROME


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,rev,rem;
clrscr();
printf("PROGRAM TO REVERSE AN INTIGER AND CHECKS WHETHER THE NUMBER IS PALINDROME OR NOT \n\n\n");
printf("Enter an intger number \n\n");
scanf("%d",&a);
b=a;
rev=0;
rem=0;
while(b!=0)
{
rem=b%10;
rev=rev*10+rem;
b=b/10;
 }
printf("\n\n");
printf("The reverse of the enetered number is = %d \n\n",rev);
if(rev==a)
printf("The number is palindrome");
else
printf("The number is not a palindrome");
getch();
}

PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR NOT

#include<stdio.h>

#include<conio.h>
void main()
{
int a,i;
clrscr();
printf("PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR NOT \n\n\n");
printf("Enter an intiger number \n\n");
scanf("%d",&a);
for(i=2;i<a;i++)
{
if(a%i==0)
{
printf("\nThe number is not prime");
goto end;
}
}
printf("\n\n");
printf("The number is prime");
end:getch();
}

PROGRAM TO FIND THE GCD AND LCM OF TWO INTEGER NUMBERS

#include<stdio.h>

#include<conio.h>
void main()
{
int a,b,pro,lcm,gcd;
clrscr();
printf("PROGRAM TO FIND THE GCD AND LCM OF TWO INTGER NUMBERS \n\n\n");
printf("Enter two intiger values \n\n");
scanf("%d %d",&a,&b);
pro=a*b;
if(a>b)
{
gcd=a-b;
lcm=pro/gcd;
 }
else
{
gcd=b-a;
lcm=pro/gcd;
}
printf("\n\n");
printf("GCD = %d \n\nLCM= %d",gcd,lcm);
getch();
}






PROGRAM ON ASCII


#include<stdio.h>

#include<conio.h>
void main()
{
char a;
int c;
clrscr();
printf("Enter your character\n");
scanf("%c",&a);
c=a;
//printf("\n %d",c);
if(c>=65&&c<=90)
printf("\nCapital letter");
else if(c>=97&&c<=122)
printf("\nSmall letter");
else if(c>=48&&c<=57)
printf("Digit");
else
printf("\nSpecial character");
//printf("\n value of c is=%d",c);
getch();
}

SIMPLE LOGIC FOR GREATEST OF THREE NO'S



#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter three nos.\n");
scanf("%d%d%d",&a,&b,&c);
((a>b)&&(a>c)?printf("%d is greatest",a):((b>c)&&(b>a)?printf("%d is greatest",b):printf("%d is greatest",c)));
getch();
}



SUM,AVERAGE,MULTIPLICATION,DIVISION,DIFFERENCE OF TWO NO'S



#include<stdio.h>
#include<conio.h>
void main()
{
       float a,b;
       float c;
       clrscr();
       printf("Enter two numbers\n");
       scanf("%f%f",&a,&b);
       c=a+b;
       printf("\nSum of two numbers is %f",c);
       c=(a+b)/2;
       printf("\nAverage of two numbers is %f",c);
       c=a*b;
       printf("\nMultiplication of two numbers is %f",c);
       c=a/b;
       printf("\nDivision of two numbers is %f",c);
       c=a-b;
      printf("\nDifference of two numbers is %f",c);
      getch();
}

SIMPLE INTEREST PROGRAM




#include<stdio.h>

#include<conio.h>
void main()

{
        float time,principle,rate,intrest;
        clrscr();
        printf("Enter the values for time in years,principle in Rs and rate \n");
        scanf("%f%f%f",&time,&principle,&rate);
        intrest=(principle*rate*time)/100;
        printf("\nInterest for given values will be Rs%f",intrest);
        getch();
}

SWAPPING OF TWO NO'S



#include<stdio.h>


#include<conio.h>




void main()


{


         int a,b,c;


         clrscr();


         printf("Enter any two numbers\n");


         scanf("%d%d",&a,&b);


         printf("\na=%d",a);

         printf("\nb=%d",b);
         c=a;
         a=b;
         b=c;
         printf("\nAfter swapping \na= %d \nb= %d",a,b);
         getch();
}

CONVERSION OF FAHRENHEIT TO CELSIUS


#include<stdio.h>
#include<conio.h>
void main()
{
         float c,f;
         clrscr();
         printf("Enter the temperature in fahrenheit\n");
         scanf("%f",&f);
         c=(5*((f-32)/9));
         printf("Temperature in Celsius will be %3.1f",c);
         getch();
}

CONVERSION OF CENTIMETER TO FEET



#include<stdio.h>


#include<conio.h>


void main()


{


        float centi,inches,feets,a,c;


        int b;


        clrscr();


        printf("Enter centimeters");


        scanf("%f",&centi);


        a=(centi/2.54);

        //printf("\n%d",a);
        feets=a/12;
        c=(a-(b*2.54));
        //c=(a%12);
        printf("%f centimeters is %d feets and %f",centi,feets,c);
        getch();
}

GREATEST OF TWO NO'S

#include<stdio.h>
#include<conio.h>
void main()
{
        int a,b;
        clrscr();
        printf("Enter any two numbers\n");
        scanf("%d%d",&a,&b);
        if(a>b)
              printf("\n%d is greater than %d",a,b);
        else if(b>a)
              printf("\n%d is greater than %d ",b,a);
        else
              printf("\nNumbers are equal");
        getch();
}

GIVEN NUMBER IS EVEN OR ODD

#include<stdio.h>
#include<conio.h>
void main()
{
         int a;
         clrscr();
         printf("Enter any number");
         scanf("%d",&a);
         if(a%2==0)
                 printf("Number is even");
         else
                 printf("Number is odd");
         getch();
}

GREATEST OF THREE NO'S

#include<stdio.h>
#include<conio.h>
void main()
{
         int a,b,c;
         clrscr();
         printf("Enter three nos.");
         scanf("%d%d%d",&a,&b,&c);
         if(a>b&&a>c)
                   printf("%d is the greatest number",a);
        else if(b>a&&b>c)
                   printf("%d id the greatest number",b);
        else if (c>a&&c>b) 
                    printf(" %d is the greatest",c);
        else
                    printf("All are equal");
        getch();
}

ARRANGE THE GIVEN NUMBERS IN ASCENDING ORDER

#include<stdio.h>
#include<conio.h>
void main()
{
           int a,b,c;
           clrscr();
           printf("Enter three nos.\n");
           scanf("%d%d%d",&a,&b,&c);
           printf("\nNumbers in ascending order will be\n");
           if(a>b&&a>c)
          {
                   if(b>c)
                         printf("%d \n%d \n%d",c,b,a);
                  else
                         printf("%d \n%d \n%d",b,c,a);
           }
           if(b>a&&b>c)
          {
                 if(a>c)
                      printf("%d \n%d \n%d",c,a,b);
                 else
                      printf("%d \n%d \n%d",a,c,b);
           }
           if(c>b&&c>a)
          {
                 if(b>a)
                      printf("%d \n%d \n%d",a,b,c);
                 else
                      printf("%d \n%d \n%d",b,a,c);
           }



           getch();
}

PROGRAM TO CALCULATE GRADE

#include<stdio.h>
#include<conio.h>
void main()
{
          int a,b,c,d,e,sum;
          float avg;
          clrscr();
          printf("Enter the marks in five subjects\n"); 
          scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
          sum=a+b+c+d+e;
          printf("Sum=%d",sum);
          avg=sum/5;
          printf("\nAverage=%f",avg);
          if(avg>=60)
         {
                printf("\nFirst division");
                getch();
                exit();
          }
         if(avg>=50)
        {
               printf("Second division");
               getch();
               exit();
         }
         if(avg>=40)
               printf("\nThird division");
         else
              printf("\nFail");
         getch();
}


PROGRAM FOR IF-ELSE-IF CONDITION 



#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter time taken by the worker to complete the work");
scanf("%d",&a);
if(a>=2&&a<=3)
printf("Effeciency is STAR");
else if(a>2&&a<=3)
printf("Effeciency is Meritorious");
else if(a>3&&a<=4)
printf("Effeciency is Adequate");
else
printf("Effeciency is Trailor");
getch();
}

SWITCH CASE PROGRAM



#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter number of month");
scanf("%d",&a);
switch(a)
{
case 1:
printf("January");
break;
case 2:
printf("February");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
}
getch();
}

FOR-LOOP PROGRAM



#include<stdio.h>
#include<conio.h>
void main()
{
long int i;
int sum=0;
clrscr();
for(i=0;i<-1000;i--)
{
sum=sum+i;
}
printf("Sum is =%ld",sum);
getch();
}

SWAPPING OF 10 NUMBERS AND THEIR AVERAGES



#include<conio.h>
#include<stdio.h>
void main()
{
int a[10],i,temp,j;
int max,min,sum=0,smax;
float avg;
clrscr();
printf("Enter 10 numbers\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
 {
  if(a[i]>a[j])
   {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
    }
  }
}
  printf("\nLargest number is %d",a[9]);
  printf("\nSecond largest is %d",a[8]);
  printf("\nSmallest number is %d",a[0]);
for(i=0;i<10;i++)
{
sum=sum+a[i];
}
avg=sum/10;
printf("\nSum=%d",sum);
printf("\nAverage is %f",avg);
getch();
}

SUM OF EVEN AND ODD NUMBERS FROM GIVEN 10 NO'S



#include<conio.h>
#include<stdio.h>
void main()
{
int a[10],i,esum=0;
int sum=0;
clrscr();
printf("Enter 10 numbers\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=10;i++)
{
 if(a[i]%2==0)
 {
  esum=esum+i;
 }
}
for(i=1;i<=10;i++)
{
 sum=sum+i;
}
printf("\nSum of even nos is=%d",esum);
printf("\nSum of odd os. is=%d",(sum-esum));
getch();
}

SQUARE OF N NUMBERS



#include<stdio.h>
#include<conio.h>
void main()
{
int a,sum=0,n;
clrscr();
printf("Enter the number");
scanf("%d",&a);
for(n=1;n<=a;n++)
{
sum=sum+(n*n);
}
printf("Sum of squares of numbers upto %d is %d",a,sum);
getch();
}


SUM OF CUBES OF N NUMBERS



# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
//variables
int i,number,sum=0;
clrscr();
printf("Enter the value:");
scanf("%d",&number);
for(i=1;i<=number;i++)
{
sum+=pow(i,3);
}
printf("Sum of square = %d",sum);
getch();
}

COUNTING NUMBER OF VOWELS IN A GIVEN STRING



#include<stdio.h>
#include<conio.h>
void main()
{
int aCount=0,eCount=0,iCount=0,oCount=0,uCount=0,conCount=0;
char ch;
clrscr();
printf("Enter ur text here : \n");
while((ch=getchar())!='\n')
{
switch(ch)
{
case 1:
ch='a';
aCount++; break;
case 2 :
ch='e';
eCount++; break;
case 3:
ch='i';
iCount++; break;
case 4:
ch='o';
oCount++; break;
case 5:
ch='u';
uCount++; break;
default:
conCount++;
}
}


printf("No of Characters \n");


printf("a\t%d,e\t%d,i\t%d,o\t%d,u\t%drest\t%d;",aCount,eCount,iCount,oCount,uCount,conCount);
getch();
}

.......................................................................................................................................................

0 comments:

Post a Comment

 
Top