• Click below to download Unit 1 programs in pdf file: -



C Practical

 

UNIT - 1

 

 

/*1 . Find the Simple Interest. Inputs are principal amount, period in

year and rate of interest.*/

 

#include <stdio.h>

 

int main()

{

    float principle, time, rate, SI;

 

    printf("Enter principle (amount): ");

    scanf("%f", &principle);

 

    printf("Enter time: ");

    scanf("%f", &time);

 

    printf("Enter rate: ");

    scanf("%f", &rate);

 

    SI = (principle * time * rate) / 100;

 

    printf("Simple Interest = %f", SI);

 

    return 0;

}

 

 

/*2. Find the area and perimeter of square and rectangle. Input the

side(s) through the keyboard.*/

 

#include <stdio.h>

 

int main()

{

    int width;

    int height;

 

    int area;

    int perimeter;

 

    printf("enter the height :");

    scanf("%d",&height);

 

    printf("enter the width :");

    scanf("%d",&width);

 

    perimeter = 2*(height + width);

            printf("Perimeter of the rectangle = %d \n", perimeter);

 

            area = height * width;

            printf("Area of the rectangle = %d square \n", area);

 

}

 

 

/*3. Accept any three numbers and find their squares and cubes.*/

 

#include <stdio.h>

 

int main()

{

    int n1,n2,n3;

 

    printf("Enter a number 1: ");

    scanf("%d", &n1);

 

    printf("Square of %d is %d\n", n1, (n1 * n1));

    printf("Cube of %d is %d\n", n1, (n1 * n1 * n1));

 

 

    printf("Enter a number 2: ");

    scanf("%d", &n2);

 

    printf("Square of %d is %d\n", n2, (n2 * n2));

    printf("Cube of %d is %d\n", n2, (n2 * n2 * n2));

 

 

    printf("Enter a number 3: ");

    scanf("%d", &n3);

 

    printf("Square of %d is %d\n", n3, (n3 * n3));

    printf("Cube of %d is %d\n", n3, (n3 * n3 * n3));

 

 

}

 

 

/*4. Write a program to enter the temperature in Fahrenheit and convert it to Celsius.[C = ((F-32)*5)/9]*/

 

#include<stdio.h>

 

void main()

{

    float celsius,fahrenheit;

 

    printf("\nEnter temperature in Fahrenheit:");

    scanf("%f",&fahrenheit);

 

    celsius=(fahrenheit - 32)*5/9;

 

    printf("\nCelsius = %f",celsius);

}

 

 

/*5. Write a program to store and interchange two numbers in

variables a and b.*/

 

#include<stdio.h>

 int main()

{

int a=10, b=20;

printf("Before swap a=%d b=%d",a,b);

 

a=a+b;

b=a-b;

a=a-b;

 

printf("\nAfter swap a=%d b=%d",a,b);

return 0;

}

 

 

/* 6.Write a program to accept an integer and display it in octal and

hexadecimal formats. */

 

 

#include <stdio.h>

 

int main()

{

    int value=2567;

 

    printf("Octal value is: %o\n",value);

    printf("Hexadecimal value is: %x\n",value);

}

 

 

/* 7. Write a program to enter text with gets() and display it using

printf() statement also find the length of the text. */

 

#include<stdio.h>

#include<string.h>

 

int main()

{

    char a[100];

    int length;

 

    printf("\n\nEnter a string you wish to calculate the length of :");

    gets(a);

 

    length = strlen(a);

 

    printf("\nThe length of the input string is: %d", length);

}

 

 

/* 8. Write a program to enter two numbers and find the smallest out

of them. Use conditional operator. */

 

#include<stdio.h>

 

void main()

{

   int a,b,small;

 

   printf("Enter two number\n");

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

 

   small = a<b?a:b;

 

   printf("Smallest among 2 Number is : %d",small);

 

}

 

 

/* 9. Write a program to enter a number and carry out modular division

operation by 2, 3 and 4 and display the remainders.*/

 

#include <stdio.h>

 

int main()

{

            int x, result;

 

            printf("enter the number : ");

            scanf("%d",&x);

 

            result = x % 2;

            printf("\n%d", result);

 

            result = x % 3;

            printf("\n%d", result);

 

            result = x % 4;

            printf("\n%d", result);

 

            return 0;

}

 

 

/* 10. Write a program to find the average temperature of five sunny

days. Assume the temperature in Celsius. */

 

#include<stdio.h>

#include<conio.h>

 

void main()

{

float a,b,c,d,e,ave;

 

printf("\nEnter The Five Days temperature : ");

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

 

ave=((a+b+c+d+e)/5);

 

printf("\nAverage temperature is :%f",ave);

 

}