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();
}

WRITE A PROGRAM TO PRINT A SUM OF FIRST N EVEN NUMBERS. (EX. = 2 + 4 + 6 + 8 + ……… + N)

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

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

            getch();
}

WRITE A PROGRAM TO PRINT A TABLE OF CONVERSION FROM FAHRENHEIT TO CENTIGRADE.

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

void main()
{
            float c, f;
           
            clrscr();
           
            printf(“\n\t_____________________”);
            printf(“\n\tFAHRENHEIT\tCENTIGRADE”);
            printf(“\n\t_____________________”);

            for(f=0.0; f<=250; f=f+25)
            {
                        /* convert farenheit into centigrade */
                        c = (f.32.0) / 1.8;
                        printf(“\n\t%10.2f\t%10.2f” ,f,c);
            }

            getch();
}

WRITE A PROGRAM TO FIND THE NUMBERS OF AND SUM OF ALL THE INTEGERS GREATER THAN 100 AND LESS THAN 200 THAT ARE DIVISIBLE BY 7.

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

void main()
{
            int I, cnt=0, sum=0;
           
            clrscr();
           
            printf(“\n\nNUMBER DIVISIBLE BY 7 BETWEEN 100 AND 200 ARE …………\n\n”);
            for(i=100; i<=200; i++)
            {
                        /*check whether the number is divisible by 7 or not */
                        if(i%7=0)
                        {
                                    cnt = cnt + 1;
                                    /* calculate sum of these numbers */
                                    sum = sum + i;
                                    printf(“%d\t” ,i);
                        }
            }
            printf(“\n\nSUM OF THESE NUMBERS IS       :           %d” ,sum);
            printf(“\n\nNUMBERS OF NUMBER BETWEEN 100 AND 200 WHICH ARE DIVISIBLE BY 7 ARE : %d” ,cnt);
            getch();
}

IF A FIVE DIGIT NUMBER IS INPUT THROUGH THE KEYBOARD, WRITE A PROGRAM TO CALCULATE THE SUM OF DIGIT. (HINT : USE THE MODULUS OPERATOR ‘%’)

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

void main()
{
            int num, sum=0, rem;
           
            clrscr();
           
            a;
            printf(“\n\nENTER ANY FIVE DIGIT NUMBER :           “);
            scanf(“%d”, &num);

            if(num <= 0)
            {
                        printf(“\nENTER POSITIVE NUMBER ONLY ……… “);
                        getch();
                        clrscr();
                        goto a
            }

            while (num > 0 )
            {
                        /* find out remainder */
                        rem = num % 10;
                        /* calculate sum of remainders */
                        sum = sum + rem;
                        /* remove last digit */
                        num = num / 10;
            }

            printf(“\n___________________”);
            printf(“\nSUM OF DIGIT OF THIS NUMBER IS = %4d” ,sum);
            printf(“\n___________________”);
           
            getch();
}


IF A FIVE DIGIT NUMBER IS INPUT THROUGH THE KEYBOARD, WRITE A PROGRAM TO REVERSE THE NUMBER.

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

void main()
{
            long int num, rem, rev=0;
           
            clrscr();
           
            a          :           /* label */
            printf(“\n\nENTER ANY FIVE DIGIT NUMBER :           “);
            scanf(“%ld”, &num);

            if(num <= 0)
            {
                        printf(“\nENTER POSITIVE NUMBER ONLY ……… “);
                        getch();
                        clrscr();
                        goto a;             /* controls transfers to label a: */
            }

            while (num > 0 )
            {
                        /* find out remainder */
                        rem = num % 10;
                        /* reverse the number */
                        rev = (rev * 10) + rev ;
                        num = num / 10;
            }

            printf(“\n___________________”);
            printf(“\REVERSE OF THIS NUMBER IS = %6ld” ,rev);
            printf(“\n___________________”);
           
            getch();
}

IF A FIVE DIGIT NUMBER IS INPUT THROUGH THE KEYBOARD, WRITE A PROGRAM TO OBTAIN THE REVERSE NUMBER AND DETERMINE WHETHER THE ORIGINAL AND REVERSED NUMBER ARE EQUAL OR NOT.

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

void main()
{
            long int num, rem, rev=0, NO;
           
            clrscr();
           
            a:        
            printf(“\n\nENTER ANY FIVE DIGIT NUMBER :           “);
            scanf(“%ld”, &num);
            no = num;
            if(num <= 0)
            {
                        printf(“\nENTER POSITIVE NUMBER ONLY ……… “);
                        getch();
                        clrscr();
                        goto a;            
            }

            while (num > 0 )
            {
                        /* find out remainder */
                        rem = num % 10;
                        /* reverse the number */
                        rev = (rev * 10) + rev ;
                        num = num / 10;
            }

            /* check whether the original & reversed number are same or not */
            if (no == rev)
            {
                        printf(“\n___________________”);
                        printf(“\ORIGINAL AND REVERSEDS  NUMBER ARE EQUAL ……………..”);
                        printf(“\n___________________”);
            }
            else
            {
                        printf(“\n___________________”);
                        printf(“\ORIGINAL AND REVERSEDS  NUMBER ARE NOT EQUAL ……………..”);
                        printf(“\n___________________”);
            }
           
            getch();
}

WRITE A PROGRAM TO PRINT ALL THE ASCII VALUES AND THEIR EQUIVALENT CHARACTERS USING A WHILE LOOP. THE ASCII VALUES VARY FROM 0 TO 255.

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

void main()
{
            int i=0, j=1;
           
            clrscr();
           
            printf(“\n\n__________________________”);
            printf(“\nASCII VALUE\tCHARACTER”);
            printf(“\n________________________\n”);

            while (i<=255)
            {
                        /* printf ascii value and characters */
                        printf(“\n%d\t\t%c” ,i ,i);
                       
                        i = i + 1;          
                        j = j + 1;
           
                        /* check whether the screen is full or not */
                        if(j == 15)
                        {
                                    printf(“\n\nPress any key ……………………………….”);
                                    getch();
                                    clrscr();
                       
                                    printf(“\n\n_________________”);
                                    printf(“\nASCII VALUE\tCHARACTER”);
                                    printf(“\n\n_________________”);
           
                                    j = 1;
                        }
            }
            getch();
}


WRITE A PROGRAM TO GENERATE MULTIPLICATION TABLE. [1 TO 10]

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

void main()
{
            int i, j;
           
            clrscr();
           
            for(i=1; i<=10; i++)
            {
                        printf(“\n\n__________________________”);
                        printf(“\nMULTIPICATION TABLE OF %d”, i”);
                        printf(“\n________________________\n”);

                        for(j=1; j<=10; j++)
                        {
                                    /* print multiplication table */
                                    printf(“\n         %d       *3d      = %3d”, i, j, i * j);
                        }
getch();
clrscr();
}
}

WRITE A PROGRAM TO FIND THE FACTORIAL VALUE OF ANY NUMBER ENTERED THROUGH THE KEYBOARD.

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

void main()
{
            long unsigned int no, fact, i;
            char ch= ‘y’;

            while(ch== ‘y’ || ch== ‘y’)
            {
                        clrscr();
           
                        lbl;
                        printf(“\nENTER NUMBER      : “);
                        scanf(“%lu” ,&no);

                        /* check whether the entered number is positive or not */
                        if(no <= 0)
                        {
                                    printf(“\n\nENTER POSITIVE NUMBER ONLY ……….”);
                                    getch();
                                    clrscr();
                                    goto lbl;
                        }
                       
                        fact = 0;

                        for(i=1; i; i<=no i++)
                        {
                                    /* calculate factorial value */
                                    fact = fact * i;
                        }

                        printf(“\n\n__________________”);
                        printf(“\nFACTORIAL VALUE of %lu = %6lu” ,no ,fact);
                        printf(“\n__________________”);
                        printf(“\n\nDO YOU WANT TO CONTINUE? [y/n] : “);
                        fflush(stdin);
                        ch=getchar();
            }
}

TWO NUMBERS ARE ENTERED THROUGH THE KEYBOARD. WRITE A PROGRAM TO FIND THE VALUE OF ONE NUMBER RAISED TO THE POWER OF ANOTHER.

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

void main()
{
            int a, b, i;
            float s;
            char ch= ‘y’;

            while(ch== ‘y’ || ch== ‘Y’)
            {
                        clrscr();

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

                        s = 1.0;
                        if(b < 0)
                        {
                                    /* calculate A raised to B for –tive number */
                                    b = b * -1;
                                   
                                    for(i=1; i<=b; i++)
                                    {
                                                s = s * a;
                                    }
                                    s = 1 / (float)s;
                        }
                        else
                        {
                                    /* calculate A raised to B for +tive number */
                                    for(i=1; i<=b; i++)
                                    {
                                                s = s * a;
                                    }          
                        }
           
                        printf(“\n\n_______________________”);
                        printf(“\n%d RAISED TO %d = %6.2f” ,a ,b ,s);
                        printf(“\n_______________________”);
                       
                        printf(“\n\nDO YOU WANT TO CONTINUE ? [y / n] : “);
                        fflush(stdin);
                        ch = getchar();
            }
}

WRITE PROGRAM TO COMPUTER AND PRINT THE LARGEST POWER OF ONE NUMBER WHICH IS LESS THEN OR EQUAL TO ANOTHER NUMBER. FOR EXAMPLE THE TWO NUMBERS ARE 3 AND 10, THE ANSWER IS 2 SINCE 3 RAISED TO 2 IS LESS THAN 10 BUT 3 RAISED TO 3 WHICH IS GREATER THAN 10.

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

void main()
{
            int a, b, i, j=1, pol=1;
            clrscr();
            x:
            printf(“\nENTER FIRST NUMBER : “);
            scanf(“%d” ,&a);
            printf(“\nENTER SECOND NUMBER : “);
            scanf(“%d” ,&b);
            /* check whether the first number us greater then second or not */
            If(a > b)
            {
                        printf(“\n FIRST NUMBER SHOULD LESS THEN OR EQUAL TO SECOND . . . . . .  “)
                        getch( ) ;
                        clrscr ( ) ;
                        goto x;
            }
            for (I = 1 ; i<=j ; I ++)
            {
                        /* calculate power */
                        po = po * a;
                        if (po > b)
                                    break;
                        j++;
            }
            printf(“\n ANSWER IS %d BECAUSE” , j-1);
            printf(“\n%d RAISED TO %d IS LESS THAN %d “ , a,j-1,b)
            printf(“\n BUT %d RAISED TO %d IS GREATER THAN %d . . . . . . “ , a, j, b) :
getch ( );
}

ANY INTEGER IS INPUT THROUGH THE KEYBOARD, WRITE A PROGRAM TO FIND OUT ALL ITS DIVISORS.
EX.= the devisors of 20 are 1,2,4,5,10,20
#include<stdio.h>
#include<conio.h>

void main()
{
            int no, i;
            char ch=’y’ ;
            clrscr( );
while (ch== ‘y’ || c== ‘Y’)
{
                        clrscr( ) ;
                        printf (“\n\nENTER ANY NUMBER TO FIND IT’S DIVISORS : “) ;
                        scanf (“%d”, &no);
                        printf(“ \n\n THE DIVISORS OF %d ARE …………\n\n” ,no) ;
                        for(i=1; i<=no; i++)
                        {
/* find out devisors of a number */
if (no % i == 0)
                                    {          
                                                printf(“ %d      “ ,i) ;
                                    }
                        }
printf(“ \n\n\nDO YOU WANT TO CONTINUE? [y/n] . . . . . .  “ ) ;
                        fflush(stdin) ;
                        scanf(“%c” , &ch);
            }
}

WRITE A PROGRAM TO PRINT ALL PRIME NUMBERS FROM 1 TO 300. [HINT : USE NESTED LOOP, BREAK & CONTINUE].
#include<stdio.h>
#include<conio.h>

void main()
{
            int  i, j, flag;
            clrscr( );
            printf (“\n\n\t\t\t__________________ “) ;
            printf (“\n\t\t\t PRIME NUMBER BETWEEN 1 AND 300”);
            printf(“ \n\t\t\t_________________ \n\n\n”) ;
            for(i=1; i<=300; i++) /* outer loop */
{
flag=0 ;
            for(j=2; j<=I -1 ; j++) /* inner loop */
{
/* check whether the number is prime or not */
if (i % j == 0)
                                    {          
                                                flag=1 ;
                                    }
                        }
if(flag ! =1)
{
            printf(“%3d\t” ,i) ;
}
}
printf(“ \n\n\Press any key] . . . . . . . . . . .  “ ) ;
            getch( );
}

WRITE A PROGRAM TO DETERMINE AND PRINT THE SUM OF THE FOLLOWING HARMONIC SERIES FOR A GIVEN VALUE OF N.
1+1/2+1/3+………… + N
#include<stdio.h>
#include<conio.h>
void main()
{
            int no, i;
            double sum=0.0 , temp;
char ch=’y’ ;
            clrscr( );
while (ch== ‘y’ || c== ‘Y’)
{
                        clrscr( ) ;
                        printf (“\n\nENTER ANY NUMBER  : “) ;
                        scanf (“%d”, &no);
                        printf(“ \n\n\n\t\tADDITION OF FIRST %d TERM OF FOLLOWING SERIES.”  ,no) ;
                        printf(“ \n\n\n\t\t\t1 + 1/2 + 1/3 + 1/4 +. . . . . . . . . . ”) ;
                        for(i=1; I <=no; i++)
                        {
                                    /* calculate value of 1/2 , 1/3 , and so on */
                                    temp = 1/ (double) I /* type casting */
                                    /* calculate sum of these numbers */
                                    sum = sum + temp;
                        }
                        printf(“\n\n\t\t\t/t SUM = %If” , Sum);
                        printf(“\n\n DO YOU WANT TO CONTINUE? [y/n] : “)
                        fflush(stdin);
                        ch=getchar( );
            }
}

WRITE A PROGRAM TO ADD FIRST SEVEN TERMS OF THE FOLLOWING SERIES USING FOR LOOP.
1/1! + 2/2! + 3/3! + …………….
#include<stdio.h>
#include<conio.h>
void main()
{
            long int i,j, fact=1
            double sum=0.0 , a=0.0;
            clrscr( );
for(i=1; i<=7; i++) /* outer loop */
{
                        fact=1;
                        for( j=1; j<=I ;j++) /* inner loop */
                        {                      
                                    /* calculate factorial */
                                    fact = fact * j ;
                                   
}
/* calculate value of 1/1! , 2/2! And so on */
a = i (double) fact ;
/* calculate sum of these numbers */
                                    sum = sum + a;
                        }
                        printf(“\n\n\n\n\t       ADDITION OF FIRST SEVEN TERM OF THE FOLLOWING SERIES.”)
                        printf(“\n\n\t\t1/1! + 2/2 ! 3/3! + 4/4! . . . . . . . . . . . . . . .");
                        printf(“\n\n\t\t\t         SUM IS = % IF” , Sum);
                        printf(“\n\n\n Press any key . . . . . . . . . . . . .”);

getchar( );
            }

WRITE A PROGRAM TO PRINT FIBONACCI SERIES. THE FIRST 7 FIBONACCI NUMBERS ARE 1, 1, 2, 3, 5, 8, 13 . . .
#include<stdio.h>
#include<conio.h>
void main()
{
            long int num, i , pre, cur , new;
            char ch= ‘y’;
            while(ch== ‘y’ || ch== ‘Y’ )
{
clrscr( );
printf(“\n\n ENTER HOW MANY NUMBERS YOU WANT IN FIBONACCI SERIES : “) ;
scanf(“%ld” ,&num);

pre = 0;
cur = 1;
new = pre + cur ;
printf(“\n\nSERIES IS ………………………….. \n”);
printf(“\n%ld, %ld, %ld, pre, cur, new);

for(i=4; i<=num; i++)
{
            /* fond out fibonacci series */
            pre = cur;
            cur = new;
            new = pre + cur;
            printf(“ %ld, “ ,new);
}
printf(“………………………………….”);

printf(“\n\nDO YOU WANT TO CONTINUE [y/n] : “);
fflush(stdin);
scanf(“%c” ,&ch);
}
}

WRITE A PROGRAM TO FIND AND PRINT FIRST N POSITIVE INTEGERS WHOSE SQUARES ARE PALINDROMES. EX.- 11^2=121, 26^2=676………………..
#include<stdio.h>
#include<conio.h>
void main()
{
            long int num, rem, rev;
            long int j=1, i=1, sq, temp;

            clrscr();

            a :  /* label */
            printf(“\n\nENTER ANY NUMBER : “);
            scanf(“%ld”, &num);
           
            /* check whether the number is positive or not */
            if(num <= 0)
            {
                        printf(“\nENTER POSITIVE NUMBER ONLY……………..”);
                        getch();
                        clrscr();
                        goto a; /* control transfers to label a: */
            }

            printf(“\nFIRST %ld NUMBER WHOSE SQUARE ARE PALINDROMES………”, num);
            printf(“\n\n––––––––––––––––––––“);
            printf(“\Nnumber\t\tSQUARE”);
            printf(“\n––––––––––––––––––––“);

            while(j <= num)
            {
                        sq = 0;
                        rev = 0;
                        rem = 0;
                        /* find out square of the number */
                        sq = i * i;
                        temp = sq;
           
                        while( sq > 0 )
                        {
                                    rem = sq % 10; /* find out remainder */

                                    /* find out reverse number */
                                    rev = (rev * 10) + rem;
                                    sq = sq / 10;
                        }

                        /* check for equality */
                        if(temp == rev)           
                        {
                                    printf(“\n%ld\t\t%ld” ,i ,temp);
                                    j = j + 1;
                        }
            }
            printf(“\n\nPress any key……….”);
            getch();
}

WRITE A PROGRAM TO PRINT THE FOLLOWING DIGIT PYRAMIDS.
1                                     1
        2      2                           1    2    1
      3    3     3                   1   2    3    2    1

#include<stdio.h>
#include<conio.h>
void main()
{
            int row, I, j, sp=40, k;
           
            clrscr();

             /* ask for number of rows */
            printf(“\n\nENTER HOW MANY ROWS YOU WANT IN PYRAMID : “);
            scanf(“%ld”, &row);
            printf(“\n\n”);
            for(i=1; i<=row; i++ /* outer loop */
            {
                        for(k=1; k<=sp; k++) /* inner loop */
                        {
                                    /* leave the spaces */
                                    printf(“ “);
                        }
                        for(j=1; j<1; j++)
                        {
                                    printf(“%d      “ ,i”);
                        }
                        printf(“\n”);
           
                        /* reduce number of spaces */
                        sp = sp – 2;
            }
            getch();
           
            clrscr();

            printf(“\n\n\n”);
           
            sp = 40;

            for(i=1; i<=row; i++)
            {
                        for(k=1; k<=sp; k++)   
                        {
                                    /* leave the spaces */
                                    printf(“ “);
                        }
                        for(j=1; j<=i; j ++)
                        {
                                    /* print in forward direction */
                                    printf(“%d “ ,j);
                        }
                        K = j-2;
                        for( ; k>=1; k -)
                        {
                                    /* print in backward direction */
                                    printf(“%d “ ,k);
                        }
                        printf(“\n”);
                        /* reduce number of spaces */
                        sp = sp – 2;
            }
            getch();
}

WRITE A PROGRAM TO PRINT FLOYED’S TRIANGLE.

1
2              3
4              5              6

#include<stdio.h>
#include<conio.h>
void main()
{
            int row, i, j, k=1;
           
            clrscr();

            printf(“\n\aENTER HOW MANY ROWS YOU WANT IN TRIANGLE : “);
            scanf(“%d”, &row);
            printf(“\n\n”);

            for(i=1; i<=row; i++ /* outer loop */
            {
                        for(j=1; j<=i; j++) /* inner loop */
                        {
                                    /* print floyed’s triangle */
                                    printf(“\t%d” ,k “);
                                    k = k + 1;
                        }                      
            }
            getch();
}

WRITE A PROGRAM TO PRODUCE THE FOLLOWING OUTPUT.

1
0              1             
1              0              1
0              1              0              1                             

#include<stdio.h>
#include<conio.h>
void main()
{
            int row, I, j, j, k;
           
            clrsr();
           
            printf(“\n\nENTER HOW MANY ROWS YOU WANT IN PYRAMID : “);
            scanf(“%d” ,&row);
            printf(“\n\n”);

            for(i=1; i<=row; i++) /* outer loop */
            {
                        /* check the position of a number in triangle */
                        if(i%2 != 0)
                                    k =1;
                        else
                                    k = 0;
                        for(j=1; j<=I; j++) /* inner loop */
                        {
                                    printf(“\t%d” ,k);
                                    if(k==1)
                                                k=0;
                                    else
                                                k=1;
                        }
                        printf(“\n”);
            }
            getch();
}


No comments

Post your comments

Powered by Blogger.