PPS-UNIT-1

SWN | PPS-Practical

Indus University

CSE Section

PPS-Practical

Unit-I:Using input output statements,operators

1.Write a program to print the address of INDUS.

#include <stdio.h>
#include <conio.h>
void main(){
printf("Adress:INDUS UNIVERSITY \n Rancharda,via shilaj \n Ahemedabad");
getch();
}

Adress:INDUS UNIVERSITY
Rancharda,via shilaj,
Ahemedabad

2. Write a program to perform basic arithmetic operators on given two numbers.

#include <stdio.h>
#include <conio.h>
void main() { float a,b;
printf("Enter the value of a:");
scanf("%f",&a);
printf("Enter the value of b:");
scanf("%f",&b);
printf("sum=%f\n",a+b);
printf("substraction=%f\n",a-b);
printf("Multiplication=%f\n",a*b);
printf("Division=%.2f\n",a/b);
getch();
}

Enter the value of a:12
Enter the value of b:12
sum=24
Multiplication=144
Division=1

3.Find the area and perimeter of square and rectangle and circle. Input the side(s) through the keyboard. (use PIE as symbolic constant)

#include <stdio.h>
#include <conio.h>
void main()
{
int side1,side2,radious;
float pi =3.14;

//For square:
int parameter;
float area;
printf("Enter the value of side1:");
scanf("%d",&side1);
printf("Enter the value of side2:");
scanf("%d",&side2);
printf("Enter the value of radious:");
scanf("%d",&radious);
area =side1*side1;
printf("area of square is:%d \n",area);
parameter =4*side1;
printf("parameter of square is:%d\n",parameter);

// For rectangle:
int parameter1;
int area1;
area1 =side1*side2;
printf("area of rectangle is:%d \n",area1);
parameter1 =(side1+side2)*2;
printf("parameter of rectangle is:%d\n",parameter1);

// For circle:
float parameter2;
float area2;
area2 =pi*radious*radious;
printf("area of circle is:%f \n",area2);
parameter2 =pi*radious*2;
printf("parameter of circle is:%f\n",parameter2);
getch();
}

Enter the value of side1:5
Enter the value of side2:6
Enter the value of radious:10
area of square is:25.000000
parameter of square is:20
area of rectangle is:30
parameter of rectangle is:22
area of circle is:314.000000
parameter of circle is:62.800003

4.Write a program to swap values of 2 variables (i) with extra variable and (ii) without using an extra variable.

#include <stdio.h>
#include <conio.h>
void main()
{

//without extra variable:
int x,y;
printf("enter the value of x: ");
scanf("%d",&x);
printf("enter the value of y: ");
scanf("%d",&y);
printf("before swap x=%d and y=%d \n",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("after swap x=%d and y=%d\n",x,y);

//with extra variable:
int a,b,c;
printf("enter the value of a: ");
scanf("%d",&a);
printf("enter the value of b: ");
scanf("%d",&b);
printf("before swap a=%d and b=%d \n",a,b);
c=a;
a=b;
b=c;
printf("after swap a=%d and b=%d \n",a,b);
getch();
}

enter the value of x: 4
enter the value of y: 6
before swap x=4 and y=6
after swap x=6 and y=4
enter the value of a: 12
enter the value of b: 13
before swap a=12 and b=13
after swap a=13 and b=12

5.Write a program to print the ASCII value of a given character.

#include <stdio.h>
#include <conio.h>
void main(){
char a;
printf("enter a character:");
scanf("%c",&a);
printf("ASCII value of %c is %d",a,a);
getch();
}

enter a character:A
ASCII value of A is 65

6.Write a program to enter the integer number and convert it into Rs and Paisa.

#include <stdio.h>
#include <conio.h>
void main(){
int rs,paisa;
printf("enter rupees:");
scanf("%d",&rs);
paisa =100*rs;
printf("%d rupees is equal to %d paisa",rs,paisa);
getch();
}

enter rupees:10
10 rupees is equal to 1000 paisa

7.Write a program to enter two numbers. Make the comparison between them with conditional operator. If the first number is greater than second perform multiplication otherwise division operation

#include <stdio.h>
#include <conio.h>
void main(){
float a,b;
printf("enter the value of a: ");
scanf("\n%f",&a);
printf("enter the value of b: ");
scanf("\n%f",&b);
a > b ? printf("a*b is %f",a*b):printf("a/b is %f",a/b);
getch();
}

enter the value of a: 1
enter the value of b: 2
a/b is 0.500000

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

#include <stdio.h>
#include <conio.h>
void main(){
float f,c;
printf("enter the value of fahrenheit: ");
scanf("\n%f",&f);
c = ((f-32)*5)/9;
printf("The celsius value is %f: ",c);
getch();
}

enter the value of fahrenheit: 200
The celsius value is 93.333336:

9.Write a program to calculate simple interest.

#include <stdio.h>
#include <conio.h>
void main()
{
float p,r,t,i;
printf("Enter the principal:");
scanf("%f",&p);
printf("Enter the rate:");
scanf("%f",&r);
printf("Enter the time:");
scanf("%f",&t);
i=(p*r*t)/100;
printf("simple interest=%f",i);
getch();
}

Enter the principal:1100
Enter the rate:6
Enter the time:2
simple interset=132.000000

10.Write a program to enter marks of five subject of a student and calculate its average, percentage.

#include <stdio.h>
#include <conio.h>
void main(){
float a,b,c,d,e,f,g;
printf("enter your marks of maths:");
scanf("\n%f",&a);
printf("enter your marks of english:");
scanf("\n%f",&b);
printf("enter your marks of hindi:");
scanf("\n%f",&c);
printf("enter your marks of gujarati:");
scanf("\n%f",&d);
printf("enter your marks of Sanskrit:");
scanf("\n%f",&e);
f =a+b+c+d+e;
printf("Average is %f",f/5);
g =(f*100)/500;
printf("Percentage is %f",g);
getch();
}

enter your marks od maths:99
enter your marks od english:33
enter your marks od hindi:56
enter your marks od gujarati:34
enter your marks od hindi:23
Average is 49.000000
Percentage is 49.000000