04 February 2022

C Practical Unit 1

 Credit: Sahil Ajmeri

Q1 . Find the Simple Interest. Inputs are principal amount, period in year and rate of interest.


#include<stdio.h>

#include<conio.h>


void main()

{

int principal,rate,years,ans;

clrscr();

printf("\t\t\t\tSIMPLE  INTREST");


printf("\n\nEnter principal amount :  ");

scanf("%d",&principal);


printf("\nEnter period in year :  ");

scanf("%d",&years);


printf("\nEnter rate of intrest :  ");

scanf("%d",&rate);


ans=(principal * rate * years) /100;


printf("\n\n\tSimple intrest =  %d",ans);


getch();

}


Q2. Find the area and perimeter of square and rectangle. Input the side(s) through the keyboard.


#include<stdio.h>

#include<conio.h>


void main()

{

int area,side,per;


int ar,l=0,b,peri;


clrscr();


printf("\t\t\tArea and Perimeter of Square");


printf("\n\n\nEnter length of side of square : ");

scanf("%d",&side);


area=(side*side);


per=(4*side);


printf("\n\n\tArea of Square  :  %d",area);


printf("\n\n\tPerimeter of Square : %d",per);


printf("\n\n\n\t\t\tAREA  AND  PERIMETER  OF  RECTANGLE");


printf("\n\n\nEnter length of rectangle  :  ");

scanf("%d",&l);

printf("\n\nEnter breadth of rectangle :  ");

scanf("%d",&b);


ar=l*b;

peri=2*(l+b);


printf("\n\n Area of rectangle :  %d ",ar);

printf("\n Perimeter of rectangle : %d",peri);


getch();

}



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

 

 

OUTPUT :

 

CODING:


#include<stdio.h>

#include<conio.h>


void main()

{

int a,b,c,sq,cub;

clrscr();

printf("\nEnter a number : ");

scanf("%d",&a);


sq=a*a;

cub=a*a*a;


printf("\nSquare  =  %d",sq);

printf("\nCube  =  %d",cub);


printf("\nEnter a number : ");

scanf("%d",&b);


sq=b*b;

cub=b*b*b;


printf("\nSquare  =  %d",sq);

printf("\nCube  =  %d",cub);



printf("\nEnter a number : ");

scanf("%d",&c);


sq=c*c;

cub=c*c*c;


printf("\nSquare  =  %d",sq);

printf("\nCube  =  %d",cub);


getch();


}


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


 


OUTPUT :


 


CODING :

#include<stdio.h>

#include<conio.h>


void main()

{

int f,c;

clrscr();


printf("Enter temperature in F :  ");


scanf("%d",&f);


c=(f-32)*5/9;


printf("\nTemp in celcus :  %d",c);


getch();

}



5. Write a program to store and interchange two numbers in variables a and b.


 

OUTPUT  :

 

CODING:

#include<stdio.h>

#include<conio.h>


void main()

{

int a,b,c;

clrscr();


printf("\nEnter value of A  :  ");

scanf("%d",&a);


printf("\nEnter value of B  :   ");

scanf("%d",&b);


printf("\n\nBefore Swaping A = %d  and   B = %d",a,b);


c=a;

a=b;

b=c;


printf("\n\n\nAfter Swaping  A = %d   and    B = %d",a,b);


getch();

}

6.  Write a program to accept an integer and display it in octal and hexadecimal formats


 

OUTPUT :

 

CODING :


#include<stdio.h>

#include<conio.h>


void main()

{

int a;

clrscr();

printf("Enter an integer  :  ");

scanf("%d",&a);


printf("\n\nDecimal  =  %d",a);

printf("\n\nOctal  =   %o",a);

printf("\n\n\Hexadecimal  =  %x",a);


getch();

}


7. Write a program to enter text with gets() and display it using printf() statement also find the length of the text



 


OUTPUT  :

 

CODING :


#include<stdio.h>

#include<conio.h>


void main()

{

char st[100];

int i=0;

clrscr();


printf("\nEnter the string  :   ");

gets(st);

printf("\nYour string is %s",st);


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

{

i++;

}


printf("\n\n\n\t\t\tYour string length  =  %d",i);


getch();


}


8. Write a program to enter two numbers and find the smallest out of them. Use conditional operator.


 

OUTPUT  :

 

CODING  :


#include<stdio.h>

#include<conio.h>


void main()

{

int no1,no2,s;

clrscr();


printf("\nEnter 1 st number  :  ");

scanf("%d",&no1);


printf("\nEnter 2 nd number  :  ");

scanf("%d",&no2);


s=(no1<=no2)?no1:no2;


printf("\nSmallest one  =  %d",s);

getch();


}


9. Write a program to enter a number and carry out modular division operation by 2, 3 and 4 and display the remainders.


 

OUTPUT  :

 

CODING  :

#include<stdio.h>

#include<conio.h>

#include<math.h>


void main()

{

int no;

clrscr();


printf("Enter Number  :  ");

scanf("%d",&no);


printf("\nModular by 2 = %d", no%2);

printf("\nModular by 3 = %d", no%3);

printf("\nModular by 4 = %d", no%4);

getch();


}


10. Write a program to find the average temperature of five sunny days. Assume the temperature in Celsius.

 

 


OUTPUT

 

CODING   :

#include<stdio.h>

#include<conio.h>


void main()

{

float a , b , d , e , f , avg ,c;

clrscr();


printf("\t\t\tEnter Five day temperatures values   ");


printf("\n\nTemperature day 1  :   ");

scanf("%f",&a);


printf("\n\nTemperature day 2  :   ");

scanf("%f",&b);


printf("\n\nTemperature day 3  :   ");

scanf("%f",&d);


printf("\n\nTemperature day 4  :   ");

scanf("%f",&e);


printf("\n\nTemperature day 5  :   ");

scanf("%f",&f);


avg=(a+b+d+e+f)/5;

c=((avg-31)*5)/9;

printf("\n\nThe average temperature of five days  =  %f",c);

getch();

}





No comments:

Post a Comment