Professional Documents
Culture Documents
LAB PROGRAMS With Screen Shot
LAB PROGRAMS With Screen Shot
LAB PROGRAMS With Screen Shot
#include<stdio.h>
#include<conio.h>
Void main()
{
float totamt,amount,subtot,distant,taxamt,quantity,value,discount,tax;
printf("\nenter the quantity of item sold:");
scanf("%f",&quantity);
printf("\n enter the value of item:");
scanf("%f",&value);
printf("\n enter the discount percentage:");
scanf("%f",&discount);
printf("\n enter the tax:");
scanf("%f",&tax);
amount=quantity*value;
distant=(amount*discount)/100.0;
subtot=amount-distant;
taxamt=(subtot*tax)/100.0;
totamt=subtot+taxamt;
printf("\n\n\n******bill******");
printf("\n quantity sold:%f",quantity);
printf("\n priceperitem:%f",value);
printf("\n amount %f",amount);
printf("\n discount:%f",distant);
printf("\n discounted total: %f",subtot);
printf("\n tax:+ %f",taxamt);
printf("\n total amount %f",totamt);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
#define pi 3.14f
void main()
float rad,area,perm;
clrscr();
scanf("%f",&rad);
area=pi*rad*rad;
perm=2*pi*rad;
getch();
OUTPUT:
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
char name[50];//or*name
printf("\n Type the name of the candidate:");
gets(name);
printf("\n Enter the age:");
scanf("%d",&age);
if(age>=18)
printf("\n %s is Eligibile for vote",name);
else
printf("\n %s is not Eligibile for vote",name);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
int big;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
big=a;
else if(b>a&&b>c)
big=b;
else
big=c;
printf("largest number is=%d",big);
return 0;
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
int main()
{
int year;
printf("enter a year:");
scanf("%d",&year);
if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
}
else
printf("%d is a leap year",year);
}
else
printf("%d is not a leap year",year);
getch();
}
OUTPUT:
#include<stdio.h>
void main()
{
int a,b,result,sq1,sq2,ch;
float divide;
clrscr();
printf("enter two integers:");
scanf("%d%d",&a,&b);
printf("1.add,2.subtrat,3.multiply,4.divide,5.sqare");
printf("\n enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
result=(a+b);
printf("sum=%d\n",result);
break;
}
case 2:
{
result=(a-b);
printf("difference=%d\n",result);
break;
}
case 3:
{
result=(a*b);
printf("mutiplication=%d\n",result);
break;
}
case 4:
{
result=a/(float)b;
printf("diviosin=%2f\n",result);
break;
}
case 5:
{
sq1=(a*a);
printf("square=%d\n",sq1);
sq2=b*b;
printf("second square number=%\n",sq2);
break;
}
}
getch();
}
OUTPUT:
#include<stdio.h>
#include<cono.h>
void main()
{
int n,orgnum,r,result=0;
printf("enter a three digit number:");
scanf("%d",&n);
orgnum=n;
while(orgnum!=0)
{
r=orgnum%10;
result+=r*r*r;
orgnum/=10;
}
if(result==n)
printf("%d is an armstrong number",n);
else
printf("%d is not an armstrong number",n);
getch();
}
OUTPUT
#include <stdio.h>
#include <math.h>
void main()
int nArray[50],wArray[50],nelem,i,j,t;
clrscr();
scanf("%d",&nelem);
printf("\nEnter %d elements\n",nelem);
for(i=0;i<nelem;i++)
scanf("%d",&nArray[i]);
wArray[i] = 0;
if(percube(nArray[i]))
wArray[i] = wArray[i] + 5;
wArray[i] = wArray[i] + 4;
if(prime(nArray[i]))
wArray[i] = wArray[i] + 3;
// Sorting an array
for(i=0;i<nelem;i++)
for(j=i+1;j<nelem;j++)
t = wArray[i];
wArray[i] = wArray[j];
wArray[j] = t;
printf("<%d,%d>\n", nArray[i],wArray[i]);
getch();
int flag=1,i;
for(i=2;i<=num/2;i++)
if(num%i==0)
flag=0;
break;
return flag;
int i,flag=0;
19
for(i=2;i<=num/2;i++)
if((i*i*i)==num)
flag=1;
break;
return flag;
OUTPUT:
/* Get a Height of Different Persons and find how many of them are are above
average */
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,sum=0,count=0,height[100];
float avg;
clrscr();
//Read Number of persons
printf("Enter the Number of Persons : ");
scanf("%d",&n);
//Read the height of n persons
printf("\nEnter the Height of each person in centimeter\n");
for(i=0;i<n;i++)
{
scanf("%d",&height[i]);
sum = sum + height[i];
}
avg = (float)sum/n;
//Counting
for(i=0;i<n;i++)
if(height[i]>avg)
count++;
//display
printf("\nAverage Height of %d persons is : %.2f\n",n,avg);
printf("\nThe number of persons above average : %d ",count);
getch();
}
OUTPUT:
#include<stdio.h>
#include<math.h>
void main(void){
int n,i,j;
float massheight[10][10];
float bmi[10];
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<2;j++){
switch(j){
case 0:
scanf("%f",&massheight[i][0]);
break;
case 1:
scanf("%f",&massheight[i][1]);
break;}
for(i=0;i<n;i++){
bmi[i]=massheight[i][0]/pow(massheight[i][1],2.0);
getch();
OUTPUT:
#include <stdio.h>
#include <string.h>
#include <conio.h>
void swap(char *a, char *b)
{
char t;
t = *a;
*a = *b;
*b = t;
}
// Main program
void main()
{
char str[100];
// Function Prototype
void reverse(char *);
int isAlpha(char);
void swap(char *a ,char *b);
clrscr();
printf("Enter the Given String : ");
// scanf("%[^\n]s",str);
gets(str);
reverse(str);
printf("\nReverse String : %s",str);
getch();
}
void reverse(char str[100])
{
// Initialize left and right pointers
int r = strlen(str) - 1, l = 0;
// Traverse string from both ends until
// 'l' and 'r'
while (l < r)
{
// Ignore special characters
if (!isAlpha(str[l]))
l++;
else if(!isAlpha(str[r]))
r--;
else
{
swap(&str[l], &str[r]);
l++;
r--;
}
}
}
// To check x is alphabet or not if it an alphabet then return 0 else 1
int isAlpha(char x)
{
return ( (x >= 'A' && x <= 'Z') ||
(x >= 'a' && x <= 'z') );
}
OUTPUT:
/*C Program to Convert the given decimal number into binary, octal and
hexadecimal numbers using user defined functions.*/
#include <stdio.h>
#include <conio.h>
char temp;
temp = *s1;
*s1 = *s2;
*s2 = temp;
int start = 0;
swap(&str[start], &str[end]);
start++;
end--;
int i = 0;
if (num == 0)
str[i++] = '0';
str[i] = '\0';
return str;
while (num != 0)
num = num/base;
reverse(str, i);
return str;
void main()
char str[100];
int n;
clrscr();
scanf("%d",&n);
getch();
OUTPUT: