1 set of c programs


All the shown programs and many others are also available in the Printed form. You can also avail the same by paying a small amount of Indian Rupees 75.00 only. You can contact us over mail for the requirement of the same. Mention the Subject matter as C-PROGRAM BOOK

YOUR FIRST ‘C’ PROGRAM.

#include<stdio.h>
#include<conio.h>

void main()
{
            clrscr();
            prinf(“\nC  programming is a Middle Level language ……….”);
            getch();
}

WRITE A PROGRAM TO DISPLAY SUM OF TWO NUMBERS.

#include<stdio.h>
#include<conio.h>

void main()
{
            /* variable declaration */
            float num1;
            float num2;
            float ans;
            clrscr();
            prinf(“\Nenter first number   : ”);
            scanf(“%f”, &num1); /* allows user to enter data from keyboard */
            printf(“\nENTER SECOND NUMBER   : “);
            scan(“%f”, &num2);
            /* add to variables */
            ans = num1 + num2;
printf(“\nSUM of %. 2f and %. 2f is : %. 2f”, num1, num2, ans);
            getch();
}

WRITE A PROGRAM TO CALCULATE SIMPLE INTEREST.

#include<stdio.h>
#include<conio.h>

Void main()
{
            float p, r, n, si;
            clrscr();
            prinf(“\NENTER PRINCIPLE     : ”);
            scanf(“%f”, &p);
            printf(“\nENTER RATE OF INTEREST  : “);
            scan(“%f”, &r);
            printf(“\nENTER NO. OF YEARS          : “);
            scanf(“%f”, &n);
            /* calculate simple interest */
            si = p * r * n / 100.0;
printf(“\NSimple Interest Rs.  = %. 2f:, si););
            getch();
}

WRITE A PROGRAM TO CALCULATE 10% BONUS OF SALARY.

#include<stdio.h>
#include<conio.h>

void main()
{
            float bonus=0.0;
            float salary;
            clarscr();
            printf(“\nENTER SALARY         : );
            scanf(“%f”, &salary);
            /* calculate 10% bonus */
            bonus = salary * 0.1;
            printf(“\nBONUS OF Rs. %. 2f Is Rs. %. 2f:, salary, bonus);
            getch();
}


WRITE A PROGRAM TO FIND VOLUME OF A CYLINDER.

#include<stdio.h>
#include<conio.h>

void main()
{
            float pi=3.14;
            float r, h, vol;
            clrscr();

            printf(“\nENTER RADIUS         : “);
            scanf(“%f” ,&r);
            printf(“\nENTER HEIGHT        : “);
            scanf(“%f” ,&h);

            vol = pi * r * r * h;
            printf(“\nVOLUME = %. 2f” ,vol);
            getch();
}


TWO NUMBERS ARE ENTERED THROUGH THE KEYBOARD FOR K.M. AND METERS. WRITE A PROGRAM TO PRINT A SUM OF THESE TWO IN METERS.

#include<stdio.h>
#include<conio.h>

Void main()
{
            float sum=0.0;
            float meter, km;

            clrscr();

            printf(“\nENTER KILOMETER  : “);
            scanf(“%f” ,&km);

            printf(“\nENTER METER         : “);
            scanf(“%f” ,&meter);

            /* convert km in to meters */
            km = km * 1000;
            /* sum of meters */
            sum = km + meter;
            printf(“\nSUM IN METER IS = %. 2f:, sum);
            getch();
}


THE DISTANCE BETWEEN TWO CITIES IS INPUT THROUGH KEYBOARD. WRITE A PROGRAM TO CONVERT AND PRINT THIS DISTANCE IN METER, FEET, INCHES, AND CENTIMETER.

#include<stdio.h>
#include<conio.h>

void main()
{
            float km, me, fe, inc, cen;

            clrscr();

            printf(“\nENTER KILOMETER  : “);
            scanf(“%f” ,&km);

            /* convert km in to meters */
            km = km * 1000;
            /* convert km into feet */
            fe = me * 3.33;
            /* convert km into inches */
            inc = fe * 12;
            /* convert km into centimeters */
            cen = me * 100;

            printf(“\nKELOMETER            = %10. 2f:, km);
            printf(“\nMETER                    = %10. 2f:, me);
            printf(“\nFEET                        = %10. 2f:, fe);
            printf(“\nINCHES                    = %10. 2f:, inc);
            printf(“\nCENTIMETER           = %10. 2f:, cen);

            getch();
};



WRITE A PROGRAM TO CALCULATE THE AVERAGE OF A SET OF N NUMBERS.

#include<stdio.h>
#include<conio.h>

void main()
{
            int no, i;
            float n, sum=0.0, avg;

            clrscr();

            printf(“\nENTER HOW MANY NUMBERS YOU WANT TO ENTER      : “);
            scanf(“%d” ,&no);

            /* ask for a number for N times */
            for(i=1; i<=no; i++)
            {
                        printf(“\nENTER %2d NUMBER          : “, i);
                        scanf(“%f” ,&n);
                        /* calculate sum of all numbers */
                        sum = sum + n;
            }

            avg = sum / no;           /* calculate average */
            printf(“\nAVERAGE OF THIS %d NUMBER IS = %. 2f” , no, avg);
            getch();

};



THE LENGTH & BREADTH OF A RECTANGLE & RADIUS OF A CIRCLE ARE INPUT THROUGH THE KEYBOARD. WRITE A PROGRAM TO CALCULATE THE AREA AND PERIMETER OF THE RECTANGLE, & THE AREA & CIRCUMFERENCE OF THE CIRCLE.

#include<stdio.h>
#include<conio.h>

void main()
{
            float pi=3.14;
            float l, b,r;
           
            clrscr();
           
            printf(“\nENTER LENGTH OF RECTANGLE      : “);
            scanf(“%f”, &l);
            printf(“\nENTER BREADTH OF RECTANGLE   : “);
            scanf(“%f” ,&b);
            printf(“\nENTER RADIUS OF CIRCLE               : “);
            scnaf(“%f” ,&r);

            /* calculate area of a rectangle */
            ar = l * b;
            /* calculate perimeter of a rectangle */
            pr = 2 * (l + b);
            /* calculate area of a circle */
            ac  = pi * r * r;
            /* calculate circumference of a circle */
            cc = 2 * pi * 2;

            printf(“\n----------------------------------------------------------“);
            printf(“\nAREA OF A RECTANGLE IS               : %. 2f” ,ar);
            printf(“\nPERIMETER OF A RECTANGLE IS     : %. 2f” ,pr);
            printf(“\nAREA OF A CIRCLE IS                       : %. 2f” ,ac);
            printf(“\nCIRCUMFERENCE OF A CIRCLE IS   : %. 2f: ,cc);
            printf(“\n---------------------------------------------------------“);
           
            getch();

};

TWO NUMBERS ARE INPUT THROUGH THE KEYBOARD INTO TWO LOCATIONS C & D. WRITE A PROGRAM TO INTERCHANGE THE CONTENTS OF C & D.

#include<stdio.h>
#include<conio.h>

void main()
{
            float c, d, temp;

            clrscr();

            printf(\nENTER VALUE OF C   : “);
            scanf(“%f” ,&c);
            printf(“\nENTER VALUE OF D : “);
            scanf(“%f” ,&d);

            /* interchange the contents of C and D */
            temp = c;
            c = d;
            d = temp;

            printf(“\n-------------------------------------“);
            printf(“\nNEW VALUE OF C    : %. 2f” ,c);
            printf(:\nNEW VALUE OF D     : %. 2f” ,d);
            printf(“\n-------------------------------------“);
           
            getch();

};

WRITE A PROGRAM TO SWAP CONTENTS OF THE TWO VARIABLES WITHOUT USING THIRD VARIABLE..

#include<stdio.h>
#include<conio.h>

void main()
{
            float a, b;

            clrscr();

            printf(\nENTER VALUE OF FIRST NUMBER     : “);
            scanf(“%f” ,&a);
            printf(“\nENTER VALUE OF SECOND NUMBER          : “);
            scanf(“%f” ,&b);

            /* swap contents of A and B */
            b = a + b;
            a = b - a;
            b = b - a;

            printf(“\n-------------------------------------“);
            printf(“\nNEW VALUE OF FIRST NUMBER      : %. 2f” ,a);
            printf(:\nNEW VALUE OF SECOND NUMBERT           : %. 2f” ,b);
            printf(“\n-------------------------------------“);
           
            getch();

};

WRITE A PROGRAM TO READ THE VALUE OF X & Y AND PRINT THE RESULT OF THE FOLLOWING EXPRESSIONS.

(A) (X+Y) / (X – Y)
(B) (X + Y) / Z
(C ) (X + Y) * (X – Y)

  
#include<stdio.h>
#include<conio.h>

void main()
{
            float x, y, ans1, ans2, ans3;

            clrscr();

            printf(\nENTER VALUE OF x    : “);
            scanf(“%f” ,&x);
            printf(“\nENTER VALUE OF y  : “);
            scanf(“%f” ,&y);

            /* calculate first expression */
            ans1 = (x + y) / (x – y);
            /* calculate second expression */
            ans2 = (x + y) / 2;
            /* calculate third rxpression */
            ans3 = (x + y) * ( x- y);

            printf(“\n-------------------------------------“);
            printf(“\n(x + y) / (x – y)         = % -6. 2f” ,ans1);
            printf(“\n(x + y) / 2                 = % -6. 2f” ,ans2);
            printf(“\n(x + y) * (x – y)         = % -6 .2f”, ans3);
            printf(“\n-------------------------------------“);
           
            getch();

};

THE STRAIGHT LINE METHOD OF COMPUTING THE YEARLY DEPRICIATION OF THE VALUE OF AN ITEM IS GIVEN BY: DEPRICIATION = (PURCHASE PRICE – SALVAGE VALUE) / YEAR OF SERVICE. WRITE A PROGRAM TO DETERMINE THE SALVAGE VALUE OF AN ITEM WHEN THE PRICHASE PRICE, YEAR OF SERVICE & ANNUAL DEPRECIATION ARE GIVEN.

#include<stdio.h>
#include<conio.h>

void main()
{
            double dep.year ,salv.pur:
            char name[20]: /* character array -/

            clrscr():

            printf( “\n\nENTER THE NAME OF THE ITEM            : “);
            scanf( “%S”,&name);

            printf( “\nENTER THE PURCHASE PRICE                    : “);
            scanf( “%I f”, ,&pur);

            printf( “\nENTER UTILITY TIME PERIOD [years]        : “);
            scanf( “%l f” ,&year);

            printf( “\nENTER DEPRICIATION OF %S                     : “,name);
            scanf(%l f”,&dep);

            /* calculate salvage value */
            salv = pur – (dep * year);

            printf( “\n\nSAIVAGE VALUE OF %s IS = %.2l f”, name, salv);

            getch();
}

WRITE A PROGRAM OF MAGIC NUMBER. (GENERATE A NUMBER USING RAND() FUNCTION, GETA NUMBER FROM USER, IF BOTH THE NUMBERS ARE SAME THEN PRINT APPROPRIATE MESSAGE.)

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
            char ch;
            int no, cno;

            clrscr();

            ch = ‘y’;

            while(ch== ‘y’ || ch== ‘y’)
            {
                        clrscr();
                        printf(“\nENTER ANY NUMBER BETWEEN 0 AND 100           : “);
                        scanf(“%d” ,&no);
                       
                        /* generate random number */
                        cno =random(100);
                       
                        /* check whether the two numbers are same or not */
                        if(no == cno)
                        {
                                    printf(“\nRIGHT GUESS”);
                        }
                        else
                        {
                                    printf(“\nWRONG GUES         : THE NUMBER IS = %d” ,cno);
                        }
                        printf(“\nDO YOU WANT TO CONTINE          : “);
                        fflush(stdin);
                        scanf(“%c”, &ch);
            }
            getch();
}


WRITE A PROGRAM THAT WILL TAKE 3 SIDES OF TRIANGLE ABC AS INPUT AND DETERMINE WHETHER THE TRIANGLE IS RIGHT-TRIANGLE OR NOT.

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
                float a,b,c,x,y,z;

                clrscr();

                printf( “\nENTER FIRST SIDE        :”);
                scanf( “%f”,&a);

                printf( “\nENTER SECOND SIDE  :”);
                scanf( “%f”,&b);

                printf( “\nENTER THIRD SIDE       :”);
                scanf( “%f”,&c

                /* calculate sqrt of sum of two sides */
                x = sqrt((a*a) + (b*b));
                y = sqrt((b*b) + (c*c));
                z = sqrt((c*c) + (a*a));

                /*check whether the triangle is right-triangle or not */
                if(c == x ll a == y ll b == z)
                {
                                printf(“\nRIGHT TRIANGLE”);
                }
                else
                {
                                printf( “\nNOT RIGHT TRIANGLE”);
                }
               
                getch();
}

WRITE A PROGRAM TO SELECT AND PRINT THE LARGEST OF THE THREE NUMBERS USING NESTED IF …..ELSE STATEMENT.

#include<stdio.h>
#include<conio.h>
                                
void main()
{
            int a,b,c;

            clrscr();

            printf( “\nENTER FIRST NUMBER       :”);
            scanf( “%d”,&a);
            printf( “\nENTER SECOND NUMBER  :”);
            scanf( “%d”,&b);
            printf( “\nENTER THIRD NUMBER      :”);
            scanf( “%d”,&c);

            printf(“\n\nMAXIMUM OUT OF THREE IS ……………”);

            /* find out largest of the three numbers */
            if (a>b)
            {
                        if(a>c)
                                    printf(“%d” ,a);
                        else
                                    printf(“%d”,c);
            }
            else
            {
                        if (b>c)
                                    printf(“%d”,b);
                        else
                                    printf(“%d”,c);
            }
            getch();
}

ANY INTEGER IS INPUT THROUGH THE KEYBOARD, WRITE A PROGRAM TO FIND OUT WHETHER IT IS AN ODD OR EVEN NUMBER.
#include<stdio.h>
#include<conio.h>
void main( )
{
            int no ;
            char c= ‘y’;
            while (c== ‘y’ || c== ‘Y’)
{
                        clrscr( ) ;
                        printf (“\n\nENTER ANY NUMBER : “) ;
                        scanf (“%d”, &no);
                        /* check whether the number is even or odd */
if (no % 2 == 0)
                                    printf(“ \nENTERD NUMBER IS EVEN ………… “) ;
                        else
                                    printf(“ \nENTERED NUMBER IS ODD …………. “) ;
                        printf(“ \n\nDO YOU WANT TO CONTINUE? [y/n] :; “ ) ;
                        fflush(stdin) ; ?* clear the buffer */
                        scanf(“%c” , &c);
            }
}

ANY YEAR IS INPUT THROUGH THE KEYBOARD, WRITE A PROGRAM TO FIND OUT WHETHER IT IS LEAP YEAR OR NOT.
#include<stdio.h>
#include<conio.h>
void main ( )
{
            int year ;
            char c= ‘y’;
            while (c== ‘y’ || c== ‘y’)
{
                        clrscr( ) ;
                        printf (“\n\nENTER ANY YEAR : “) ;
                        scanf (“%d”, &year);
                        /* check whether the year is a leap year or not */
If (year % 4 == 0)
                                    Printf(“ \n ENTERD YEAR IS A LEAP YEAR ………… “) ;
                        else
                                    Printf(“ \nENTERED YEAR IS NOT A LEAP YEAR …………. “) ;
                        printf(“ \n\nDO YOU WANT TO CONTINUE? [y/n] : “ ) ;
                        fflush(stdin) ;
                        scanf(“%c” , &c);
            }
}


WRITE A PROGRAM TO FIND ROOTS OF QUADRATIC EQUATION. THE PROGRAM REQUESTS THE USER TO INPUT THE VALUES OF A, B AND C AND OUTPUTS ROOT 1 AND ROOT 2.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
            float a,b,c, delta, root1, root2;
            char ch= ‘y’;
            while (ch== ‘y’ || c== ‘Y’ )
{
                        clrscr( ) ;
                        printf (“\n\nENTER VALUE OF a : “) ;
                        scanf (“%f”, &a);
print(“ \nENTERD VALUE OF b :  “) ;
                        scanf (“%f”, &b);
printf(“ \nENTER VALUE OF C :  “) ;
scanf (“%f”, &c);
/* calculate the cale if delta */
delta = (b * b) . (4 * a * c ) ;
/* check for root */
if(delta < 0)
{
            printf(“\n - - - - - - - - - - - - - - - - - - - - - - - - - “) ;
            printf(“\nROOTS ARE IMAGINERY ……………… “) ;
            printf(“\ n- - - - - - - - - - - - - - - - - - - - - - - - - “) ;
}
if(delta ==0)
{
            root1 = -b / (2 * a );
            printf(“\ n- - - - - - - - - - - - - - - - - - - - - - - - - “) ;
            printf(“\nROOTS ARE EQUAL ……………… “) ;
            printf(“\Nroot1 IS = %8.2f”,root1) ;
            printf(“\Nroot2 IS = %8.2f”,root2) ;
            printf(“\ n- - - - - - - - - - - - - - - - - - - - - - - - - “) ;
}
if(delta > 0 )
{
            root1 = ( -b +sqrt (delta)) / (2 * a );
            root2 = ( -b - sqrt (delta)) / (2 * a );  
printf(“\ n- - - - - - - - - - - - - - - - - - - - - - - - - “) ;
            printf(“\nROOT1 IS = %8.2f”,root1) ;
            printf(“\nROOT2 IS = %8.2f”,root2) ;
            printf(“\ n- - - - - - - - - - - - - - - - - - - - - - - - - “) ;
}
printf(“ \n\nDO YOU WANT TO CONTINUE? [y/n] : “ );
                        fflush(stdin) ;
                        ch=getchar( );
            }
}

ANY CHARACTER IS ENTERED THROUGH THE KEYBOARD, WRITE A PROGRAM TO DETERMINE WEATHER THE CHARACTER ENTERED IA A CAPITAL LETTER, A SMALL CASE LETTER, A DIGIT OR A SPECIAL SYMBOL.
#include<stdio.h>
#include<conio.h>
void main ( )
{
            int asci ;
            char ch,ans= ‘y’;
            clrscr( ) ;
while (ans == ‘y’ || ans == ‘y’)
{
                        clrscr( ) ;
                        printf (“\nENTER ANY CHARACTER …………… “) ;
                        fflush(stdin) ;
scanf (“%c”, &ch);
                        /* convert character into it’s ascii value */
asci = ch;
                        /* check for type of character */
                        if(asci>=65 && asci<=90)
                        {
                               printf(“ \n CHARACTER ENTERD [%c] IS A CAPITAL LETTER …………. “ , ch) ;
}
if(asci>=97 && asci<=122)
{
            printf(“ \nCHARACTER ENTERD [%c] IS A SMALL LETTER …………. “ , ch) ;
}
if(asci>=48 && asci<=57)
                                {
                                                printf(“ \nCHARACTER ENTERD [%c] IS A DIGIT …………. “ , ch) ;
                        }
            if(asci>=0 && asci<=47 || asci>=58 && asci <=64 || asci>=91 && asci <=96 ||
asci>=123 && asci <=127)
{
            printf(“ \nCHARACTER ENTERD [%c] IS A SPECIAL SYMBOL …………. “, ch) ;
                                }
printf(“ \n\nDO YOU WANT TO CONTINUE? [y/n] : “ );
                                    fflush(stdin) ;
                                    ans = getchar( );
            }
}

WRITE A PROGRAM THAT READS A CHARACTER FROM KEYBOARD AND PRINT IT IN REVERSE CASE. E.G. – IF THE INPUT IS UPPER CASE, THE OUTPUT WILL BE LOWER CASW AND VICE-VERSA.
#include<stdio.h>
#include<conio.h>
void main ( )
{
            int asci , new;
            char ch,ans= ‘y’;
            while (ans == ‘y’ || ans== ‘Y’)
{
                        crscr( ) ;
                        x : /* label */
printf (“\nENTER ANY CHARACTER …………… “) ;
                        fflush(stdin) ;
scanf (“%c”, &ch);
                        /* convert character into it’s ascii value */
asci = ch;
                        if(asci>=65 && asci<=90)
                        {
                                    /* convert upper case into lower case */
                                    new = asci + 32;
                                    printf(“\n REVERSE CASE OF [%c] IS [%c] “ , asci , new);      
                        }
                        else
                        {
                                    if(asci>= 97 && asci<=122)
                                    {
                                                new = asci – 32;
                                                /* convert lower case into upper case */
                                                printf(“\nREVERSE CASE OF [%c] “ ,asci ,new);
                                    }
                                    else
                                    {
                                                printf(“\n\nENTER SMALL OR CAPITAL LETTER ONLY . . . . . . “) ;
                                                getch( ) ;
clrscr ( ) ;
goto x; /* control transfers to label X: */
                                    }
                        }
                        printf(“\nDO YOU WANT TO CONTINUE? [y/n]         : “);
                        fflush(stdin);
                        ans=getchar();
            }
}

WRITE A PROGRAM TO PRINT ‘COMPUTER WORLD’ 5 TIMES.

#include<stdio.h>
#include<conio.h>

void main()
{
            int I;

            clrscr();

            /* this loop will execute 5 times */
            for(i=0; i<=4; i++)
            {
                        printf(“\n[%d] COMPUTER WORLD”, i+1);
            }
            getch();
}

WRITE A PROGRAM DISPLAY A SUM OF FIRST 10 NATURAL NUMBERS.

#include<stdio.h>
#include<conio.h>

void main()
{
            int i, sum=0 ;

            clrscr();

            for(i=1; i<=10; i++)
            {
                        /* calculate sum of first 10 numbers */
                        sum = sum + 1;
            }
                        printf(“\nSUM OF 1 TO 10 IS  :           %d” ,sum);
            }
            getch();
}

WRITE A PROGRAM TO PRINT A SUM OF FIRST N ODD NUMBERS. (EX. = 1 + 3 + 5 + 7 + ……… + N)

#include<stdio.h>
#include<conio.h>

void main()
{
            int i=1, sum=0, odd = 1; ;
            clrscr();
            printf(“\nENTER NUMBER      :           “);
            scanf(“%d” ,&num);
           
            while(i <= num)
            {
                        /* calculate sum of first N odd numbers */
                        sum = sum + odd;
                        /* next odd number */
                        odd = odd + 2;
                        i = i + 1;
            }
            printf(“\nSUM OF FIRST %d ODD NUMBERS IS          :           %d”, num, sum);

            getch();
}

No comments

Post your comments

Powered by Blogger.