Monday, 20 October 2014

C Program that Calculates the area of a square by giving length of the side from the user

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
         int a,l;
         printf("\nEnter the length of the Square:");
         scanf("%d",&l);
         a=l*l;
         printf("\nArea of the Square is %d",a);
}


Input/Output:

Enter the length of the Square:10

Area of the Square is 100

Write a program to read three numbers from the user and find the highest number

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
        int x,y,z,h;
        clrscr( );
        printf("\nEnter Three Numbers:");
        scanf("%d%d%d",&x,&y,&z);
        h=((x>y)&&(x>z))?x:(y>z)?y:z;
        printf("\nHighest Number is %d",h);
        getch( );
}


Input/Output:

Enter Three Numbers:10
20
30

Highest Number is 30




Write a program to read two numbers from the user and find highest number

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
           int x,y,h;
           clrscr( );
           printf("\nEnter two Numbers:");
           scanf("%d%d",&x,&y);
           h=(x>y)?x:y;
           printf("\nHighest Number is %d",h);
           getch( );
}


Input/Output:

Enter two Numbers: 10
20

Highest Number is 20




C program to Print the following Output

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

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
          int i,j;
          for(i=1;i<=10;i++)
          {
                     if(i==7)
                     {
                              for(j=1;j<=3;j++)
                              {
                                          printf("%d  ",i);
                               }
                       }
                       printf("%d  ",i);
            }
}


Input/Output:

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



Sunday, 19 October 2014

C Program for finding Second Largest Number in the given array of elements

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,j,temp,n;
        clrscr( );//clear the screen contents
printf("\nEnter size of the Array:");
scanf("%d",&n);
printf("\nEnter elements to Array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)// Sorting logic begins
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}//ends
printf("Second largest: %d",a[n-2]);
getch();
}


Input/Output:

Enter size of the Array: 5

Enter elements to Array:5
4
8
2
1
Second largest: 5



C Program for Given Number is Even or Odd using Bit-Wise Operators

Program:

#include<stdio.h>  //header file
#include<conio.h>  //header file
int odd(int); // funtion proto type
void main( )
{ //main function begins
          int n;
          printf("\nEnter a Number:");
          scanf("%d",&n);
          if(odd(n))
          {
                printf("\n Given Number is ODD");
           }
           else
           {
                printf("\n Given Number is EVEN");
            }
}//main function ends
int odd(int n)
{
           if(n&1)
           {
                      return 1;
            }
            else
            {
                       return 0;
             }
}

Input/Output:

Enter a Number: 5

Given Number is ODD







Saturday, 6 September 2014

C Program to print the first N Natural Numbers in Reverse Order

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
             int c,n;
             printf("\nEnter N value: ");
             scanf("%d", &n);
             c = n;
             while(c>0)
             {
                      printf("\n %d",c);
                      c--;
              }
              getch( );
}

Input/Output:

Enter N Value: 5
5
4
3
2
1



C Program to Print the first N Natural Numbers

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
           int c=1,n;
           printf("\n Enter N value: ");
           scanf("%d", &n);
           while(c<=n)
           {
                    printf("\n %d",c);
                    c++;
            }
            getch( );
}

Input/Output:

Enter N value: 5
1
2
3
4
5

C Program to print the given message N times


Program:

#include<stdio.h>
#include<conio.h>
typedef int count;
void main( )
{
            count c = 1,n;
            printf("\n Enter N value: ");
            scanf("%d", &n);
            A: printf("\n Let US Code in C");
                 c++;
                 if( c<=n)
                      goto A;
             getch();
}

Input/Output:

Enter N value: 5

Let US Code in C

Let US Code in C

Let US Code in C

Let US Code in C

Let US Code in C

C language Tutorials-1



--> 1 Byte  =  8 bits

--> 1 Kilo Byte  =  2^10 Bytes = 1024 bytes

--> 1 Mega byte = 2^10 KB = (2^10)*(2^10) bytes = 2^20 bytes

--> 1 Giga Byte = 2^10 MB = (2^10)*(2^10)*(2^10) bytes = 2^30 bytes

--> A variable just storage a location which is capable of storage some table.

-->The rules for naming a variable are else following.

--> The Variable name should start with
         1) Alphabets and it can be followed by any number of  alphabets or digits without any other                     special symbols except "___"(underscore).
        2) The Variable names should not match with the keywords
        3) Variable names should be unique i.e , no two variables should have same name within a program.
--> There are some words provided by "C" language which has a free defined meaning and are referred as key words (or) reserved words
-->  There are 32 Keywords in C language. The keywords provided by "C" languages are as follows

             Auto, break, case, char, const, continue, do, default, double, else, enum, extern, far, for, float, goto, int, if, long, near, return, register, struct, static, short, signed, switch, typedef, union, unsigned, void, while


--> "C" language is a case-sensitive language i.e, it consider both upper case and lower case symbols are different.

--> A program is set of sequence of instruction which perform a free defined task.

--> Each and Every statement should be terminated with a semicolon(;).

--> A "C" Program is a combination of functions with a special function called main()  from which they execution start
        ( ) --> Parenthesis
       { } --> Braces
        [ ] --> Sub-script
   
For Example:
                      main( )
                     {
                             f(3);
                             f(2);
                             f(1);
                      }
                      f1(arg list)
                      {
                               statements;
                      }
                      f2(arg list)
                      {
                                statements;
                      }
                      f3(arg list)
                      {
                                statements
                      }