pages

Saturday, March 28, 2020

C Progrmming Slip 5

BCA PRACTICAL SLIPS SOLUTION


Slip5
Q1. Write a C program to accept dimensions length (l), breadth(b) and height(h) of a
cuboids and display surface area and volume (Hint : surface area=2(lb+lh+bh ),
volume=lbh ) [15 Marks]
#include <stdio.h>
int main()
{
float length, width, height;
float SA, Volume;
printf("\nPlease Enter Length, Width and Height of a Cuboid\n");
scanf("%f %f %f",&length, &width, &height);
SA = 2 * (length * width + length * height + width * height);
Volume = length * width * height;
printf("\n The Surface Area of a Cuboid = %.2f\n",SA);
printf("\n The Volume of a Cuboid = %.2f\n",Volume);
}

------------------------------------------------------------------------

Q2.Write a program which accepts a sentence from the user and alters it as follows: Every space
is replaced by *, case of all alphabets is reversed, digits are replaced by ? [25 Marks]
# include<stdio.h>
 /* Function to get sum of digits */
int main()
{
 int c = 0;
 char ch, s[100];
 printf("Input a string\n");
 gets(s);
 for(c=0;s[c] != '\0';c++) {
 ch = s[c];
 if (ch >= 'A' && ch <= 'Z')
s[c] = s[c] + 32;
 else if (ch >= 'a' && ch <= 'z')
 s[c] = s[c] - 32;
 else if(s[c]==' ')
 s[c] = '*';
 else if(s[c]>0 || s[c]<9)
 s[c] = '?';
 }
 puts(s);
 return 0;
}

No comments:

Post a Comment