BCA PRACTICAL SLIPS SOLUTION
Slip 3
Q1. Write a C program to accept temperatures in Fahrenheit (F) and display it in Celsius(C)
and Kelvin (K) (Hint: C=5.0/9(F-32), K = C + 273.15) [15 Marks]
#include<stdio.h>
#include<conio.h>
int main()
{
float cel,fer,kel;
printf("Enter Temperature in Fahrenheit :");
scanf("%f",&fer);
cel= (fer-32)/1.8 ;
printf("Celsius = %f \n",cel);
kel = (fer-32)/1.8 + 273.15 ;
printf("Kelvin = %f \n",kel);
return (0) ;
}
------------------------------------------------------------------------
Q2. Write a menu driven program to perform the following operations on strings using standard
library functions: [25 Marks]
Length of String 2. Copy String 3. Connect Two Strings 4. Compare two strings
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20],str1[20];
int ch,i,j;
clrscr();
do
{
printf("\n****MENU****");
printf("\n1:Find Length");
printf("\n2:Copy the Strings");
printf("\n3:Compare the Strings");
printf("\n4:Concatenate the Strings");
printf("\n5:Exit");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the string: ");
scanf("%s",&str);
i=strlen(str);
printf("\nThe Length of given string is: %d",i);
break;
case 2:
printf("\nEnter the first string: ");
scanf("%s",&str);
printf("\nEnter the second string: ");
scanf("%s",&str1);
strcpy(str,str1);
printf("\nThe Copied string is: %s",str);
break;
case 3:
printf("\nEnter the first string: ");
scanf("%s",&str);
printf("\nEnter the second string: ");
scanf("%s",&str1);
j=strcmp(str,str1);
if(j==0)
{
printf("\nThe string is same");
}
else
{
printf("\nThe string is not same");
}
break;
case 4:
printf("\nEnter the first string: ");
scanf("%s",&str);
printf("\nEnter the second string: ");
scanf("%s",&str1);
strcat(str,str1);
printf("\nThe Concatenated string is: %s",str);
break;
case 5:
exit(0);
break;
}
}
while(ch!=5);
getch();
}
No comments:
Post a Comment