POP LAB 1-5
POP LAB 1-5
POP LAB 1-5
#include<stdio.h>
#include<stdlib.h>
int main()
int num1,num2;
char choice;
float res;
scanf("%c",&choice);
scanf("%d",&num1);
scanf("%d",&num2);
switch(choice)
case'+' : res=num1+num2;
break;
case'-' : res=num1-num2;
break;
case'*': res=num1*num2;
break;
case'%' : res=num1%num2;
break;
Output:
vsk-10@ubuntu:~/VSK$ ./a.out
result:10 + 20 = 30.000000
vsk-10@ubuntu:~/VSK$ ./a.out
result:10 - 20 = -10.000000
vsk-10@ubuntu:~/VSK$ ./a.out
10
result:10 * 20 = 200.000000
vsk-10@ubuntu:~/VSK$ ./a.out
result:10 / 20 = 0.500000
vsk-10@ubuntu:~/VSK$ ./a.out
result:10 % 20 = 10.000000
2:An electricity board charges the following rates for the use of electricity: for
the first 200 units 80 paise per unit: for the next 100 units 90 paise per unit:
beyond 300 units Rs 1 per unit. All users are charged a minimum of Rs. 100 as
meter charge. If the total amount is more than Rs 400, then an additional
surcharge of 15% of the total amount is charged. Write a program to read the
name of the user, the number of units consumed, and print out the charges.
#include<stdio.h>
int main()
char name[10];
float unit,
metercharge=100;
scanf("%s",name);
printf(“Unit consumed:\n”);
scanf(“%f”,&unit);
if(unit<=200)
metercharge=metercharge+(unit*.80);
else if(unit>300)
metercharge=metercharge+(200*0.80)+(100*0.90)+((unit -300)*1);
if(metercharge>400)
metercharge=metercharge+(metercharge*0.15);
MeterCharge:%f",name,unit,metercharge);
return 0;
Output:
vsk-10@ubuntu:~/VSK$ ./a.out
Unit consumed:150
Name: Ram
MeterCharge: 220.000000
vsk-10@ubuntu:~/VSK$ ./a.out
Name: Som
MeterCharge: 305.000000
vsk-10@ubuntu:~/VSK$ ./a.out
unit Consumed:500
Name: Sham
MeterCharge: 632.500000
3: Write a C Program to display the following by reading the number of rows as input.
#include <stdio.h>
void main()
int i,j,n;
scanf("%d",&n);
for(i=0;i<=n;i++)
for(j=1;j<=n-i;j++)
printf(" ");
for(j=1;j<=i;j++)
printf("%d",j);
for(j=i-1;j>=1;j--)
printf("%d",j);
printf("\n");
#include<stdio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
printf("enter the size of Matrix A\n");
scanf("%d%d",&m,&n);
printf("enter the size of Matrix B\n");
scanf("%d%d",&p,&q);
if(n == p)
{
printf("Enter the elements of matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of matrix B:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
for(j=0;j<q;j++)
c[i][j]=0; for(k=0;k<n;k++)
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
else
printf("\n");
5: Develop a program to sort the given set of N numbers using Bubble sort.
#include<stdio.h>
void main()
{
int i,j,n,temp,a[6];
printf("\nEnter the size of an array : ");
scanf("%d",&n);
printf("\nEnter the elements of an array : \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] =temp;
}
}
}
printf("The elements of the array after sorting : \n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}