Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, February 9, 2011

C9 : Polinomial equation


Back to Home   &  C


//To find polinomial equation 3X2 + 2X + 3

#include<stdio.h>
#include<conio.h>
void main()
      {
      clrscr();
      float a,b;
      printf("Enter the value of X\n");
      scanf("%f",&a);
      b=3*a*a+2*a+3;
      printf("Result=%f",b);
getch();
}
-----------------------------------------------------------------
Output
Enter the value of X
2
Result=19
===============================================

Back to Home   &  C

C8 : Area of a triangle


Back to Home   &  C


//To find Area of a triangle 

#include<stdio.h>
#include<conio.h>
void main()
   {
   clrscr();
   float a=3.14,b,c;
   printf("Enter Radius\n");
   scanf("%f",&b);
   c=a*b*b;
  printf("Area=%f",c);
getch();
}
-----------------------------------------------------------
Output
Enter radius
3
Area=28.26
===============================================


Back to Home   &  C

C7 : Even-Odd numbers Print/check/sum


Back to Home   &  C


A ))) //Program to print even numbers upto a given limit


Method -1
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=2,n,e;
printf("Enter the limit\n");
scanf("%d",&n);
printf("Even nos upto %d\n",n);
for(i=2;i<=n;i=i+2)
         {
printf("%d\n",i);
         }
getch();
}

------------------------------------
Output
Enter the limit (Enter your choice)
8
Even numbers upto 8 
2
4
6
8



Method -2

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,
printf("Enter the limit\n");
scanf("%d",&n);
for(i=2;i<=n;i++)
     {
      if(i%2==0)
            {
             printf("%d\n",i)
            }
     }
getch();
}



------------------------------------
Output
Enter the limit (Enter your choice)
8
2

4
6
8

===============================================


B ))) //Check whether the given number is odd or even


#include<stdio.h>
#include<conio.h>
void main()
{
   clrscr();
   int i=1;
   printf("Enter the no\n");
   scanf("%d",&i);
   if(i%2==0)
      {
      printf("%d is even\n");
      }
   else
      {
      printf("%d is odd\n");
      }
   getch();
   }

------------------------------------------------------------------
Output
Enter the number
5
5 is odd

===============================================

C ))) ////Print the total number of odd or even within a given range(1 to 10)


#include<stdio.h>
#include<conio.h>
void main()
{
   clrscr();
   int i=1,o,e;
   printf("Enter the number\n");
   scanf("%d",&i);
   for(i=1;i<=10;i=i+1)
     {
      if(i%2==0)
         {
e=e+1;
         }
     else
         {
o=o+1;
         }
     }
   printf("Total no of even is %d,and odd is %d",e,o);
   getch();
}

------------------------------------------------------------------
Output
Enter the number
9
Total number of even is 4,and odd is 5
===============================================

Back to Home   &  C



C6 : Displaying numbers(While,for.Do-While & Arrays)


Back to Home   &  C


A )))) //Display 4 numbers(While Loop)
#include<stdio.h>
#include<conio.h>
void main()
          {
          clrscr();
          int i=1;
          while(i<=4)
                  {
                  printf("%d\n",i);
                  i=i+1;
                 }
        getch();
         }
---------------------------------------------
Output
1
2
3
4
===============================================
B )))) //Display 4 numbers(for loop)
#include<stdio.h>
#include<conio.h>
void main()
          {
          clrscr();
          int i=1;
          for(i=1;i<=4;i=i+1)
              {
               printf("%d\n",i);
               }
   getch();
}

---------------------------------------
Output

1
2
3
4


==============================================


C ))) //To display any 10 numbers using arrays(Our choice)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[10];
printf("Enter 10 nos\n");
for(i=0;i<10;i++)
         {
scanf("%d",&a[i]);
         }
         printf("The 10 nos are:\n");
        for(i=0;i<10;i++)
               {
       printf("%d\n",a[i]);
               }
getch();
}
------------------------------------------------------------
Output
Enter 10 numbers (Enter 10 numbers as per your choice)
1
2
3
4
5
6
8
4
5
6
The 10 numbers are :
1
2
3
4
5
6
8
4
5
6
===============================================

D ))) //To display 10 numbers using arrays 


#include<stdio.h>
#include<conio.h>
void main()
        {
clrscr();
int i,a[10];
printf("Displaying 10 nos using arrays:\n");
for(i=0;i<=10;i++)
{
printf("%d\n",a[i]);
}
getch();
}
(May be some error in output)
===============================================

E ))) //Display n nos using Arrays(any numbers upto the given limit)
(Note the difference in the output of E and F)

#include<stdio.h>
#include<conio.h>
void main()
           {
clrscr();
int i,n,a[100];
printf("How many nos you want to display\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("%d",a[i]);
}
getch();
}
------------------------------------------------------------
Output
How many nos you want to display
3
1
2
3
===============================================
F ))) //Display n nos using Arrays(any numbers upto the given limit)
(Note the difference in the output of E and F)

#include<stdio.h>
#include<conio.h>
void main()
           {
clrscr();
print i,n,a[100];
printf("How many nos you want to display\n");
scanf("%d",&n);
printf("Enter %d no\n",n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("The nos are:\n");
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
------------------------------------------------------------
Output
How many nos you want to display
2
Enter 2 numbers
3
4
The nos are:
3
4
===============================================
G ))) //Display n numbers(Do-While)



#include<stdio.h>
#include<conio.h>
void main()
{
   clrscr();
   int i=1,n;
   printf("How many nos you want to display\n");
   scanf("%d",&n);
   do
   {
      printf("%d\n",i);
      i=i+1;
   }
   while(i<=n);
getch();
}
---------------------------------------------------------

Output
How many nos you want to display
3
1
2
3
===============================================
H ))) //Display n numbers(For loop) (As per our choice)
Refer Eg:J

#include<stdio.h>
#include<conio.h>
void main()
{
   clrscr();
   int i=1,n;
   printf("How many nos you want to display\n");
   scanf("%d",&n);
   for(i=1;i<=n;i=i+1)
   {
      printf("%d\n",i);
   }
   getch();
}
---------------------------------------------------------
Output
How many nos you want to display
3
1
2
3
===============================================
I ))) //Display n numbers(While loop)


#include<stdio.h>
#include<conio.h>
void main()
{
   clrscr();
   int i=1,n;
   printf("How many nos you want to display\n");
   scanf("%d",&n);
   while(i<=n)
   {
      printf("%d\n",i);
      i=i+1;
   }
   getch();
}

---------------------------------------------------------
Output
How many nos you want to display
3
1
2
3
==============================================
J ))) //Display n numbers(For loop) - Not as per our choice
Refer Eg:H



#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
for(i=1;i<=10;i=i+1)
{
printf("%d\n",i);
}
getch();
}

---------------------------------------------------------
Output
1
2
3
4
5
6
7
8
9
10

==============================



Back to Home   &  C