pages

Monday, March 30, 2020

C Progrmming Slip 8



BCA PRACTICAL SLIPS SOLUTION


Slip8

Q1. A cashier has currency notes of denomination 1, 5 and 10. Write a C program to accept
the withdrawal amount from the user and display the total number of currency notes of
each denomination the cashier will have to give. [15 Marks]
#include<stdio.h>
int main()
{
int w,x,y,z;
printf("enter withdrow amount : ");
scanf("%d",&w);
x=w/10;
w=w%10;
y=w/5;
w=w%5;
z=w;
printf("note of 10 : %d\n",x);
printf("note of 5 : %d\n",y);
printf("note of 1 : %d\n",z);
}

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

Q2. Write a menu driven program to perform the following operation on m*n
Matrix [25 Marks]
1. Calculate sum of upper triangular matrix elements
2. Calculate sum of diagonal elements
#include <stdio.h>
void main()
{
 int fig_code;
 float side, base, length, breadth, height, area, radius;
 printf("-------------------------\n");
 printf(" 1 --> sum of upper\n");
 printf(" 2 --> sum of dignola\n");
 printf("-------------------------\n");
 int i, j, a[10][10], sum, rows, columns;
 printf("\nEnter the number of Rows : ");
 scanf("%d", &rows);
 printf("\nEnter the number of Columns : ");
 scanf("%d", &columns);
 //Accept the Elements in Matrix
for (i = 0; i < rows; i++)
 for (j = 0; j < columns; j++) {
 printf("\nEnter the Element a[%d][%d] : ", i, j);
 scanf("%d", &a[i][j]);
 }
 printf("Enter the Figure code\n");
 scanf("%d", &fig_code);
 switch(fig_code)
 {

 case 1:
 sum = 0;
 for (i = 0; i < rows; i++)
 for (j = 0; j < columns; j++) {
 // Condition for Upper Triangle
 if (i < j) {
 sum = sum + a[i][j];
 }
 }
printf("sum of upper=%d",sum);
 break;
 case 2:
sum = 0;
 for (i = 0; i < rows; i++)
 for (j = 0; j < columns; j++) {
 // Condition for Upper Triangle
 if (i == j) {
 sum = sum + a[i][j];
 }
 }
printf("sum of digonal=%d",sum);
 break;

 default:
 printf("Error in figure code\n");
 break;
 }
}

No comments:

Post a Comment