C record v.2

  • Upload
    suga555

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

  • 8/3/2019 C record v.2

    1/88

    LEAP YEAR

    AIM:

    To determine if the given year is leap year or not using conditional operator.

    ALGORITHM:

    1. Start the program.

    2. Get the year from the user.

    3. Check the condition :( ( (yr%400) ==0) || ( (yr%4)==0 ) && ( (yr%100)!=0)) and assign

    V=1 if its True or V=0 if its False.

    4. Print the result as it is a leap year if V=1 or not a leap year otherwise.

    5. Stop the program.

  • 8/3/2019 C record v.2

    2/88

    PROGRAM:

    #include

    #include

    void main()

    {

    int yr,v;

    clrscr();

    printf("\n\nEnter the year:");

    scanf("%d",&yr);

    v=( ( (yr%400) ==0) || ( (yr%4)==0 )&&( (yr%100)!=0) )?1:0;

    if(v==1)

    printf("The year %d is a Leap Year!!",yr);

    else

    printf("The year %d is not a Leap Year!!",yr);

    getch();}

    OUTPUT:

  • 8/3/2019 C record v.2

    3/88

    Enter the year:2016

    The year 2016 is a Leap Year!!

    Enter the year:2017

    The year 2017 is not a Leap Year!!

    CHECKING CHARACTER

    AIM :

  • 8/3/2019 C record v.2

    4/88

    Write a program using conditional operator to find if the input is a Special Symbol or not.

    ALGORITHM:

    1. Start the program.

    2. Get the character from the user into a.

    3. Check for the ascii value of the character:

    if((a>=65)&&(a=97)&&(a=48)&&(a

  • 8/3/2019 C record v.2

    5/88

    {

    char a;

    clrscr();

    printf("enter the character: \n");

    scanf("%c",&a);

    if((a>=65)&&(a=97)&&(a=48)&&(a=0)&&(a=58)&&(a=91)&&(a=123)&&(a

  • 8/3/2019 C record v.2

    6/88

    You have entred a Special Symbol

    Enter the symbol:p

    the entered character is a lower case

    Enter the symbol:8

    the entered character is a number

    LIBRARY FINE CALCULATION

    AIM:

    Write a program to calculate fine for book return in Library.

    ALGORITHM:

  • 8/3/2019 C record v.2

    7/88

    1. Start the program.

    2. Get the value of Days from the user.

    3. Calculate fine as:

    if(days=6)&&(days10)&&(days30)

    Fine=0

    4. If fine! =0, print the fine amount, else print Membership Cancelled.

    5. Stop the program.

    PROGRAM:

    #include

    #include

    void main()

    {

  • 8/3/2019 C record v.2

    8/88

    int days,fine;

    clrscr();

    printf("Enter the no. of days:");

    scanf("%d",&days);

    if(days=6)&&(days10)&&(days30)

    {fine=0;}

    if(fine!=0)

    printf("Your fine is = Rs.%d",fine);

    elseprintf("Your membership has been cancelled!!!!");

    getch();

    }

    OUTPUT:

    Enter the no. of days:25

    Your fine is = Rs.125

  • 8/3/2019 C record v.2

    9/88

    TYPES OF TIRANGLE

    AIM:

    Write a program to check whether a Triangle is Isosceles, Scalene, Equilateral or Right.

    ALGORITHM:

    1. Start the program.

  • 8/3/2019 C record v.2

    10/88

    2. Get the sides of the Triangle from the user.

    3. Check the following condition:

    If all the sides are equal, its an Equilateral Triangle.

    If any 2 sides are equal, its an Isosceles triangle.

    If the sum of square of any 2 sides is equal to the square of the third side, its a

    Right Triangle.

    If none of the sides are equal, its a Scalene Triangle.

    4. Print the Triangle type.

    5. Stop the program.

    PROGRAM:

    #include

    #include

    void main()

    {

    int s1,s2,s3,sq1,sq2,sq3;

  • 8/3/2019 C record v.2

    11/88

    clrscr();

    printf("\n\nEnter the 1st side:");

    scanf("%d",&s1);

    printf("\n\nEnter the 2nd side:");

    scanf("%d",&s2);

    printf("\n\nEnter the 3rd side:");

    scanf("%d",&s3);

    sq1=s1*s1; sq2=s2*s2; sq3=s3*s3;

    printf("\n\nThe Triangle is:");

    if((s1==s2)&&(s2==s3)&&(s3==s1))

    printf("Equilateral");

    else if((s1==s2)||(s2==s3)||(s3==s1))

    printf("Isosceles");

    else if(((sq1+sq2)==sq3)||((sq1+sq3)==sq2)||((sq2+sq3)==sq1))

    printf("Right");else if((s1!=s2)&&(s2!=s3)&&(s3!=s1))

    printf("Scalene");

    }

    getch();

    }

    OUTPUT:

    Enter the 1st side: 3

    Enter the 2nd side: 4

    Enter the 3rd side: 5

  • 8/3/2019 C record v.2

    12/88

    The Triangle is:Right

    PRIME NUMBERS

    AIM:

    Write a program to print all the Prime numbers from 1 to 300 using BREAK and

    CONTINUE.

    ALGORITHM:

    1. Start the program.

  • 8/3/2019 C record v.2

    13/88

    2. Begin 2 loops with variables i=0,

  • 8/3/2019 C record v.2

    14/88

    for(i=1;i

  • 8/3/2019 C record v.2

    15/88

    167 173 179 181 191 193 197 199 211 223

    227 229 233 239 241 251 257 263 269 271

    277 281 283 293

    SUM OF SERIES

    AIM:

    Write a program to calculate the sum of the series:1/1!+2/2!+.+7/7!

    ALGORITHM:

    1. Start the program.

    2. Declare and define a float function fact ().

    3. Start a loop with i=1,i

  • 8/3/2019 C record v.2

    16/88

    PROGRAM:

    #include

    #include

    float fact(float n)

    {

    float f;

    if((n==0)||(n==1))

    return 1;

    else

    {

    f=n*fact(n-1);

    return f;

    }

    }

  • 8/3/2019 C record v.2

    17/88

    void main()

    {

    float i,d=0;

    clrscr();

    for(i=0;i

  • 8/3/2019 C record v.2

    18/88

    ARMSTRONG NUMBERS

    AIM:

    Write a program to print the Armstrong numbers from 1 to 300

    ALGORITHM:

    1. Start the program.

    2. Start a loop with c=1,c

  • 8/3/2019 C record v.2

    19/88

    PROGRAM :

    #include

    #include

    void main()

    {

    int r;

    long c, sum = 0, temp;

    clrscr();

    printf("Following armstrong numbers are found from 1 to 300:\n\n");

    for( c = 1 ; c

  • 8/3/2019 C record v.2

    20/88

    sum = sum + r*r*r;

    temp = temp/10;

    }

    if ( c == sum )

    printf("%ld\n", c);

    sum = 0;

    }

    getch();

    }

    OUTPUT:

    Following Armstrong numbers are found from 1 to 300:

    1

    153

  • 8/3/2019 C record v.2

    21/88

    SORTING USING FUNCTION

    AIM:

    Write a function to sort an array.ALGORITHM:

    1. Start the program.

    2. Write a sort function sort () with the parameters n=size of the array and ar[]=array

    name.

    3. Print the sorted array inside the function.

    4. Start the main program and read the size of the array and the array elements from the

    user.

    5. Call the function sort (array name [],size).

    6. Stop the program.

  • 8/3/2019 C record v.2

    22/88

    PROGRAM:

    #include

    #include

    void sort(int ar[],int n){

    int t,i,j;

    for(i=0;i

  • 8/3/2019 C record v.2

    23/88

    {

    printf("\n%d",ar[i]);

    }

    }

    void main()

    {

    int ar[10],i,n;

    clrscr();

    printf("Enter the no. of elements in the Array:");

    scanf("%d",&n);

    printf("\n\nEnter the elements:");

    for(i=0;i

  • 8/3/2019 C record v.2

    24/88

    FACTORIAL

    AIM:

    Write a program to find the factorial of a number using recursion.

    ALGORITHM:

    1. Start the program.

    2. Write an function fact() with the parameter n=number.

    3. If n=0 or n=1, return 1.

    4. Else, f=n*fact(n-1),return f.

    5. In the main program, get the number n from the user.

    6. Call the function fact(n);

    7. Print the factorial.

    8. Stop the program.

  • 8/3/2019 C record v.2

    25/88

    PROGRAM:

    #include

    #include

    int fact(int n)

    {int f;

    if((n==0)||(n==1))

    return 1;

    else

    {

    f=n*fact(n-1);

    return f;

    }

    }

    void main()

    {

    int n,f;

    clrscr();

    printf("Enter the number:");

    scanf("%d",&n);

    f=fact(n);

  • 8/3/2019 C record v.2

    26/88

    printf("\n %d! = %d",n,f);

    getch();

    }

    OUTPUT:

    Enter the number:5

    5! = 120

  • 8/3/2019 C record v.2

    27/88

    SUM OF NUMBERS

    AIM:

    Write a program using recursive functions to find the sum of first 25 numbers.

    ALGORITHM:

    1. Start the program.

    2. Write a recursive function sum() as:s=s+n+sum(n-1)

    3. Get the number upto which the sum has to be calculated from the user and call the

    function.

    4. Print the sum.

    5. Stop the program.

  • 8/3/2019 C record v.2

    28/88

    PROGRAM:

    #include

    #include

    int sum(int n)

    {

    int s=0;

    if(n==0)

    return 0;

    else{

    s=s+n+sum(n-1);

    return s;

    }

    }

    void main()

    {

    int n,s1;

    clrscr();

    printf("Enter the last no. :");

    scanf("%d",&n);

    s1=sum(n);

    printf("\n\nThe sum of the first %d no.s using Recursion is: %d",n,s1);

    getch();

    }

  • 8/3/2019 C record v.2

    29/88

    OUTPUT

    Enter the last no. :25

    The sum of the first 25 no.s using Recursion is: 325

  • 8/3/2019 C record v.2

    30/88

    SUM OF DIGITS WITH RECURSION

    AIM:

    Write a program to find the sum of the digits of a 5 digit number using Recursion.

    ALGORITHM:

    1. Start the program.

    2. Write a recursive function sum() as:

    r=n%10;

    s=s+r+sum(n/10);

    return s;

    3. Read the % digit number from the user in the main program and call the function sum().

    4. Print the sum.

    5. Stop the program.

  • 8/3/2019 C record v.2

    31/88

    PROGRAM:

    #include

    #include

    long sum(long n)

    {

    long s=0,r;

    if(n==0)

    return 0;

    else{

    r=n%10;

    s=s+r+sum(n/10);

    return s;

    }

    }

    void main()

    {

    long n,s=0;

    clrscr();

    printf("Enter a 5 digit no.:");

    scanf("%ld",&n);

    s=sum(n);

    printf("\n\n The sum of digits = %ld",s);

    getch();

    }

  • 8/3/2019 C record v.2

    32/88

    OUTPUT:

    Enter a 5 digit no.:45678

    The sum of digits = 30

  • 8/3/2019 C record v.2

    33/88

    SUM OF DIGITS

    AIM:

    Write a program to find the sum of the digits of a 5 digit number without using

    Recursion.

    ALGORITHM:

    1. Start the program.

    2. Read the 5 digit number from the user.

    3. Calculate the sum of the digits as:

    while(n>0)

    r=n%10;

    s=s+r;

    n=n/10;

    4. Print the sum.

    5. Stop the program.

  • 8/3/2019 C record v.2

    34/88

    PROGRAM:

    #include

    #include

    void main(){

    long n,r,s=0;

    clrscr();

    printf("Enter the 5 digit no.:");

    scanf("%ld",&n);

    while(n>0)

    {

    r=n%10;

    s=s+r;

    n=n/10;}

    printf("\n\nThe sum of the digits is = %ld",s);

    getch();

    }

  • 8/3/2019 C record v.2

    35/88

    OUTPUT:

    Enter the 5 digit no.:45678

    The sum of the digits is = 30

  • 8/3/2019 C record v.2

    36/88

    SWAPPING USING POINTERS

    AIM:

    Write a program to swap two numbers using pointers.

    ALGORITHM:

    1. Start the program

    2. Read the numbers from the user.

    3. Pass the address of the numbers to the function swap.

    4. Use the temporary variable and pointer values to swap the values.

    5. Stop the program.

  • 8/3/2019 C record v.2

    37/88

    PROGRAM:

    #include

    #include

    void swap(int *a,int *b)

    {

    int t;

    t=*a;*a=*b;

    *b=t;

    printf("\n\n A = %d \t\t B = %d",*a,*b);

    }

    void main()

    {

    int a,b;

    clrscr();

    printf("Enter A =");

    scanf("%d",&a);printf("\nEnter B =");

    scanf("%d",&b);

    printf("\nAfter Swapping");

    swap(&a,&b);

    getch();

    }

  • 8/3/2019 C record v.2

    38/88

    OUTPUT:

    Enter A =100

    Enter B =200

    After Swapping

    A = 200 B = 100

  • 8/3/2019 C record v.2

    39/88

    INTERCHANGE THE CONTENTS

    AIM:

    Write a program to interchange the contents of the variables without using a temporary

    variable.

    ALGORITHM:

    1. Start the program.

    2. Read the numbers a,b from the user.3. Swap the numbers by adding and subtracting the values from the input values.

    4. Print the Swapped numbers.

    5. Stop the program.

  • 8/3/2019 C record v.2

    40/88

  • 8/3/2019 C record v.2

    41/88

    OUTPUT:

    Enter A=100

    Enter B=200

    After interchanging:

    A = 200 B = 100

  • 8/3/2019 C record v.2

    42/88

    SUM OF DIGITS USING RECURSION

    AIM:

    Write a program to find the sum of the digits of a 5 digit number.

    ALGORITHM:

    1. Start the program.

    2. Read the 5 digit number from the user.

    3. Calculate the sum of the digits by using the modulus operation.

    4. Print the sum.

    5. Stop the program.

  • 8/3/2019 C record v.2

    43/88

    PROGRAM:

    #include

    #include

    long sum(long n)

    {

    long s=0,r;

    if(n==0)

    return 0;

    else

    {

    r=n%10;

    s=s+r+sum(n/10);

    return s;}

    }

    void main()

    {

    long n,s=0;

    clrscr();

    printf("Enter a 5 digit no.:");

    scanf("%ld",&n);

    s=sum(n);

    printf("\n\n The sum of digits = %ld",s);getch();

    }

  • 8/3/2019 C record v.2

    44/88

    OUTPUT:

    Enter a 5 digit no.:45678

    The sum of digits = 30

  • 8/3/2019 C record v.2

    45/88

    GREATEST OF THREE NUMBERS

    AIM:

    Write a program to find the greatest of 3 numbers using conditional operators.

    ALGORITHM:

    1. Start the program.

    2. Read the 3 numbers a,b and c form the user.

    3. Assign gr8s value as:

    gr8=((a>b)&&(a>c))?a:((b>c)&&(b>a))?b:c;

    4. Print gr8.

    5. Stop the program.

  • 8/3/2019 C record v.2

    46/88

    PROGRAM:

    #include

    #include

    void main()

    {

    int a,b,c,gr8;

    clrscr();

    printf("Enter the 3 no.s:");

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

    gr8=((a>b)&&(a>c))?a:((b>c)&&(b>a))?b:c;

    printf("\n\nThe greatest of %d, %d & %d is: %d",a,b,c,gr8);

    getch();

    }

    OUTPUT:

    Enter the 3 no.s:

  • 8/3/2019 C record v.2

    47/88

    40

    60

    20

    The greatest of 40, 60 & 20 is: 60

    PALINDROME OF NUMBERS

    AIM:

    Write a program to check if a given number is a Palindrome or not.

  • 8/3/2019 C record v.2

    48/88

    ALGOROTHM:

    1. Start the program.

    2. Read the number n from the user.

    3. Using while loop and modulus operation get the reverse value of the input.

    4. If input and reverse are same, print they are palindrome.

    5. Else print they are not palindrome.

    6. Stop the program.

    PROGRAM:

    #include

    #include

    void main()

  • 8/3/2019 C record v.2

    49/88

    {

    int n,r,s=0,t;

    clrscr();

    printf("Enter the no.:");

    scanf("%d",&n);

    t=n;

    while(n>0)

    {

    r=n%10;

    s=s*10+r;

    n=n/10;

    }

    printf("\nThe entered no: %d",t);

    printf("\nThe revresed no: %d",s);

    if(t==s)printf("\nThe no.s are a Palindrome!!!");

    else

    printf("\nThe no.s are not a Palindrome!!!");

    getch();

    }

    OUTPUT:

    Enter the no.:1234

    The entered no: 1234

    The revresed no: 4321

  • 8/3/2019 C record v.2

    50/88

    The no.s are not a Palindrome!!!

    FINDING THE YOUNGEST AMOUNG THREE

    AIM:

    Write a program to find the youngest of Ram, Shyam and Ajay when their ages are given.

    ALGORITHM:

    1. Start the program.

  • 8/3/2019 C record v.2

    51/88

    2. Get the ages of Ram, Shyam and Ajay from the user.

    3. Find the youngest of 3 as:

    ((r

  • 8/3/2019 C record v.2

    52/88

    clrscr();

    printf("Enter the ages of Ram, Shyam & Ajay:\n");

    scanf("%d%d%d",&r,&s,&a);

    printf("\n\nThe youngest of Ram, Shyam & Ajay is: ");

    ((r

  • 8/3/2019 C record v.2

    53/88

    MATRIX OPERATIONS

    AIM:

    To perform addition, subtraction and multiplication operations on a matrix in a menu based

    program.

    ALGORITHM

    1. Start the program.

    2. Read the 2 matrices from the user.

  • 8/3/2019 C record v.2

    54/88

    3. Read the operation to be performed on the matrices.

    4. Based on the choice from Step 3, perform addition, subtraction or multiplication on the

    matrices.

    5. Display the result.

    6. Stop the program.

    `

    PROGRAM

    #include

    #include

    void main()

    {

    int a[2][2],b[2][2],c[2][2],i,j,k,ch;

    clrscr();

    printf("\n\nEnter the Matrix A:");

    for(i=0;i

  • 8/3/2019 C record v.2

    55/88

    for(j=0;j

  • 8/3/2019 C record v.2

    56/88

    }

    break;

    }

    case 3:

    {

    for(i=0;i

  • 8/3/2019 C record v.2

    57/88

    }

    OUTPUT

    Enter the Matrix a:

    1

    2

    3

    5

    Enter the Matrix B:

    2

    1

    3

    4

  • 8/3/2019 C record v.2

    58/88

    1.Addition

    2.Subtraction

    3.Multiplication

    4.Display

    5.Exit

    Enter your choice: 1

    1.Addition

    2.Subtraction

    3.Multiplication

    4.Display

    5.Exit

    Enter your choice: 4

    The Resultant Matrix:

    3 3

    6 9

    1.Addition

    2.Subtraction

    3.Multiplication

    4.Display

    5.Exit

    Enter your choice: 2

    1.Addition

    2.Subtraction

    3.Multiplication

    4.Display

    5.Exit

  • 8/3/2019 C record v.2

    59/88

    Enter your choice: 4

    The Resultant Matrix:

    -1 1

    0 1

    Enter your choice: 3

    1.Addition

    2.Subtraction

    3.Multiplication

    4.Display

    5.Exit

    Enter your choice: 4

    The Resultant Matrix:

    8 23

    8 23

    1.Addition

    2.Subtraction

    3.Multiplication

    4.Display

    5.ExitEnter your choice:5

    INPUTTING DATA INTO A FILE AND DISPLAYING IT

    AIM:

    To create a file, store data into it and display the data based on some condition.

    ALGORITHM

    1. Start the program.

    2. Open a file in write mode and write the data into the file.

    3. Close the file.

    4. Open the file in read mode and display the data that satisfies the condition.

    5. Close the file

    6. Stop the program

  • 8/3/2019 C record v.2

    60/88

    PROGRAM

    #include

    #include

    void main()

    {

    struct donor

    {

    char name[20],adrs[30];

    int age,btyp;

    }d[10];

    FILE *f1;

    int n,i;

    clrscr();

    f1=fopen("donor","w");

  • 8/3/2019 C record v.2

    61/88

    if(f1==NULL)

    {

    puts("CAnnot open");

    exit();

    }

    printf("Enter the no. of records:");

    scanf("%d",&n);

    for(i=1;i

  • 8/3/2019 C record v.2

    62/88

    OUTPUT

    Enter the no. of records:3

    Enter the details of P.NO: 1

    Name:Sam

    Address:Chennai

    Age:24

    BLOOD type:2

    Enter the details of P.NO: 2

    Name:Rex

  • 8/3/2019 C record v.2

    63/88

    Address:Mumbai

    Age:27

    BLOOD type:5

    Enter the details of P.NO: 3

    Name:Leo

    Address:Delhi

    Age:20

    BLOOD type:1

    The records in the file are:

    Name:Sam

    Address:Chennai

    Age:24

    B.Type:2

    Name:Leo

    Address:Delhi

    Age:20

    B.Type:1

  • 8/3/2019 C record v.2

    64/88

    COPYING THE CONTENTS OF A FILE TO ANOTHER

    AIM

    To write a program to copy the contents of one file to another.

    ALGORITHM

    1. Start the program.

    2. Open a file in write mode and write some text into it.

    3. Close the file.

    4. Open the file in read mode.

    5. Open another file in write mode and write the contents of the file opened in step 4 onto

    this file.

    6. Close both the files.

    7. Stop the program.

  • 8/3/2019 C record v.2

    65/88

    PROGRAM

    #include

    #include

    void main(){

    FILE *fs,*fd;

    char ch;

    clrscr();

    fs=fopen("source","w");

    fprintf(fs,"This file has the source content");

    fclose(fs);

    fs=fopen("source","r");

    if(fs==NULL)

    {

    puts("Cannot open");

    exit();

    }

    fd=fopen("desti","w");

    if(fd==NULL)

  • 8/3/2019 C record v.2

    66/88

    {

    puts("Cannot open");

    exit();

    }

    while((ch=getc(fs))!=EOF)

    {

    //fprintf(fd,"%c",ch);

    putc(ch,fd);

    }

    fclose(fs);

    fclose(fd);

    getch();

    }

    OUTPUT

    File: SOURCE

    This file has the source content

    File: DESTI

    This file has the source content

  • 8/3/2019 C record v.2

    67/88

    STRUCTURE IMPLEMENTATION

    AIM

    To write a program to implement the usage of array of structure.

    ALGORITHM

    1. Start the program.

    2. Create the structure to store student details like name, course and marks of 3 subjects.3. Create an array as the structure variable.

    4. Read data from the user in to the structure using loops.

    5. Calculate the total and average.

    6. Display the details, total and average.

    7. Stop the program.

  • 8/3/2019 C record v.2

    68/88

    PROGRAM

    #include

    #include

    void main()

    {

    struct student

    {

    char name[20],course[5];float m[4];

    }s[4];

    int i,j;

    float tot[3]={0,0,0},avg[3]={0,0,0};

    clrscr();

    printf("\n\nSTUDENT DETAILS");

    for(i=0;i

  • 8/3/2019 C record v.2

    69/88

    avg[i]=(tot[i]/3);

    }

    printf("\n\nNAme\t\tCourse\t\tTOtal\t\tAverage");

    printf("\n-------------------------------------");

    for(i=1;i

  • 8/3/2019 C record v.2

    70/88

    Enter MArk 2: 78

    Enter MArk 3: 89

    NAme Course TOtal Average

    -----------------------------------------------------------

    Tom MCA 257.000000 85.666664

    Brad M.Tec 239.000000 79.666664

    Phil MSc 252.000000 84.000000

    STRING MANIPULATION

    AIM

    To write a program to perform string operations based on a menu.

    ALGORITHM

    1. Start the program.

    2. Read the string from the user.

    3. Read the users choice on what to count in the string, number of characters, words or the

    occurrence of a particular character.4. Perform operation and display result.

    5. Stop the program.

  • 8/3/2019 C record v.2

    71/88

    PROGRAM

    #include

    #include

    #include

    void main()

    {

    char str1[20],chara;

    int w,c,count=0,ch,i,len;

    clrscr();

    printf("\n\nString Operations!!!");

    printf("\n\nEnter the string:");gets(str1);

    do

    {

    printf("\n\t1.Words\n\t2.Characters\n\t3.Counting the occurence of a character\n\t4.Exit");

    printf("\n\nEnter what to count:");

    scanf("%d",&ch);

    switch(ch)

    {

    case 1:

    {

    w=0;

    i=0;

    while(str1[i]!='\0')

    { if(str1[i]== ' ')

  • 8/3/2019 C record v.2

    72/88

    w++;

    i++;

    }

    printf("The total number of words are %d",w+1);

    break;

    }

    case 2:

    {

    c=0;for(i=0;str1[i]!='\0';i++)

    {

    i=c++ ;

    }

    printf("\n\nNo. of characters in the string: %d ",c);

    break;

    }

    case 3:

    {

    printf("\nEnter the character to search for:");

    scanf("%s",&chara);

    len=strlen(str1);

    count=0;

    for(i=0;i

  • 8/3/2019 C record v.2

    73/88

    {

    exit();

    }

    }

    }while(ch!=0);

    getch();

    }

    OUTPUT

    String Operations!!!

    Enter the string:boy has a big blue ball

    1.Words

    2.Characters

    3.Counting the occurence of a character

    4.Exit

    Enter what to count:1The total number of words are 6

    1.Words

    2.Characters

    3.Counting the occurence of a character

    4.Exit

    Enter what to count:2

    No. of characters in the string: 23

    1.Words

    2.Characters

    3.Counting the occurence of a character

    4.Exit

    Enter what to count:3

  • 8/3/2019 C record v.2

    74/88

    Enter the character to search for:b

    The character b is present 4 times

    1.Words

    2.Characters

    3.Counting the occurence of a character

    4.Exit

    Enter what to count:

    4

    BILL GENERATION

    AIM

    To write a program to generate a bill with discount for purchases made for more than Rs.1000.

    Display a menu of items and get the order from the user

    ALGORITHM

    1. Start the program.

    2. Display the menu of items available and their price to the user.

    3. Read the number of items the user wishes to buy.

    4. Calculate the total amount.

    5. If the amount>=1000, discount=10% of amount.

    6. Display the bill amount.7. Stop the program

  • 8/3/2019 C record v.2

    75/88

    PROGRAM

    #include

    #include

    void main()

    {

    int pen,hard,stylus,p,h,s;

    float amt,disc;

    clrscr();

    p=350;h=1200;s=750;

    printf("Item\t\tPrice\nPen Drive\t%d\nHard Disk\t%d\nStylus\t\t%d",p,h,s);

    printf("\n\nEnter the no. of items you wish to buy:\n(Enter 0 to skip an item)");printf("\n\tPen Drive:");

    scanf("%d",&pen);

    printf("\n\tHard Disk:");

    scanf("%d",&hard);

    printf("\n\tStylus:");

    scanf("%d",&stylus);

    amt=((pen*p)+(hard*h)+(stylus*s));

    if(amt>=1000)

    {

    disc=((amt*10)/100);

    amt=amt-disc;

    }

    printf("\n\nYour Bill\n---------\n%f",amt);

    getch();

    }

  • 8/3/2019 C record v.2

    76/88

    OUTPUT

    Item Price

    Pen Drive 350Hard Disk 1200

    Stylus 750

    Enter the no. of items you wish to buy:

    (Enter 0 to skip an item)

    Pen Drive:2

    Hard Disk:0

    Stylus:1

    Your Bill

    ------------

    1305.000000

  • 8/3/2019 C record v.2

    77/88

    SALARY CALCULATION

    AIM

    To write a program to find the gross salary of an employee when his basic salary is given.

    The salary is calculated as:

    If basic pay=1500, HRA=500 and DA=98%

    ALGORITHM

    1. Start the program.

    2. Read the basic pay from the user.

    3. Calculate the HRA and DA according to the condition.

    4. Gross salary=basic pay+HRA+DA.

    5. Display gross pay.

    6. Stop the program.

  • 8/3/2019 C record v.2

    78/88

    PROGRAM

    #include

    #include

    void main()

    {float bp,hra,da,gp;

    clrscr();

    printf("ENter your Basic Pay:");

    scanf("%f",&bp);

    if(bp=1500){

    hra=500;

    da=(bp*0.98);

    }

    gp=bp+hra+da;

    printf("\n\Gross Salary: %0.2f",gp);

    getch();

    }

  • 8/3/2019 C record v.2

    79/88

    OUTPUT

    ENter your Basic Pay:1500

    Gross Salary: 3470.00

  • 8/3/2019 C record v.2

    80/88

  • 8/3/2019 C record v.2

    81/88

    PROGRAM

    #include

    #include

    void main()

    {

    float km;

    clrscr();

    printf("Enter the distance between two cities:");scanf("%f",&km);

    printf("\n distance in meter is: %f\n",(km*1000));

    printf("\n distance in centimeter is: %f\n",(km*100000));

    printf("\n distance in feet is: %f\n",(km*3200.03));

    printf("\n distance in inches is: %f\n",(km*39370.7));

    getch();

    }

  • 8/3/2019 C record v.2

    82/88

    OUTPUT:

    Enter the distance between two cities:9

    distance in meter is:9000.00000

    distance in centimeter is:9000.00000

    distance in feet is:28800.270000

    distance in inches is:354336.300000

  • 8/3/2019 C record v.2

    83/88

    CONVERTING TEMPERATURE

    AIM

    To covert the given temperature from Fahrenheit to Celsius.

    ALGORITHM

    1. Start the program.

    2. Read temperature.

    3. Convert it into Celsius and display.

    4. Stop the program.

  • 8/3/2019 C record v.2

    84/88

    PROGRAM:

    #include

    #include

    void main()

    {

    float f,c;

    clrscr();

    printf("Enter the temperature of Chennai in Fahrenheit:");

    scanf("%f",&f);

    c=(f-32)/1.8;

    printf("the temperature in Celsius is: %f",c);

    getch();}

  • 8/3/2019 C record v.2

    85/88

    OUTPUT:

    Enter the temperature of Chennai in Fahrenheit: 135

    the temperature in Celsius is:57.222221

  • 8/3/2019 C record v.2

    86/88

    AREA CALCULATION

    AIM

    Write a program to find the area and perimeter of a rectangle and area and circumference of a

    circle.

    ALGORITHM

    1. Start the program.

    2. Read the sides and radius of the triangle and circle respectively.

    3. Calculate the area and perimeter of the rectangle and area and circumference of the

    circle.

    4. Display the result.

    5. Stop the program.

  • 8/3/2019 C record v.2

    87/88

    PROGRAM

    #include

    #include

    void main()

    {

    int l,b,r,pr,ar;

    float cc,ac;

    clrscr();

    printf("enter the length and breath of the rectangle:");

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

    printf("radius of the circle:");

    scanf("%d",&r);

    pr=2*(l+b);ar=l*b;

    cc=2*3.14*r;

    ac=3.14*r*r;

    printf("\n the element of rectangle is:%d",pr);

    printf("\n the area of rectangle is:%d",ar);

    printf("\n the circumference of circle is:%f",cc);

    printf("\n the area of circle is:%f",ac);

    getch();

    }

    OUTPUT:

  • 8/3/2019 C record v.2

    88/88

    enter the length and breath of the rectangle :2 3

    radius of the circle:5

    the element of rectangle is:10

    the area of rectangle is:6

    the circumference of circle is:31.4000

    the area of circle is:78.5000