Skip to main content

MINI TEST, MANIT Bhopal Dec 2022

 


Question 1:

Write a program that prints the word addition as "MANIT" using the ASCII value of individual characters.

Code

#include <stdio.h>

int main() {

    char a='M', b='A', c='N',d='I',e='T';

    int sum;

    sum = a+b+c+d+e;

    printf("Sum of %c+%c+%c+%c+%c is %d"

    ,a,b,c,d,e,sum);

     return 0;

}

Output:

Sum of M+A+N+I+T is 377


 

Question 2:
Write a program to find MIN and MAX without using IF-ELSE and take three values from the user.

 

Code

#include <stdio.h>

main()

{

    int a, b, c, Max, Min ;

 

    printf("Enter three numbers : ") ;

 

    scanf("%d %d %d", &a, &b, &c) ;

 

    Max = a > b ? (a > c ? a : c) : (b > c ? b : c) ;

    Min = a < b ? (a < c ? a : c) : (b < c ? b : c) ;

 

    printf("\nThe Biggest number is : %d \nThe Smallest number is : %d", Max, Min) ;

}

Output:

Enter three numbers : 45

87

12

The Biggest number is : 87

The Smallest number is : 12

 


Question 3:
Write a program to calculate profit or loss; where take input cost price and selling price.

Code

#include <stdio.h>

int main()

{

    int cp,sp, amt;

    printf("Enter cost price: ");

    scanf("%d", &cp);

    printf("Enter selling price: ");

    scanf("%d", &sp);

    if(sp > cp)

    {

        amt = sp - cp;

        printf("Profit = %d", amt);

    }

    else if(cp > sp)

    {

        amt = cp - sp;

        printf("Loss = %d", amt);

    }

    else

    {

        printf("No Profit No Loss.");

    }

    return 0;

}

Output:

Enter cost price: 1589

Enter selling price: 1200

Loss = 389

 



Question 4:
Write a programme to left shift by two bits of any number and also check the number dividing by 4 or not.

Code

#include <stdio.h>

 main()

{

    long number,  after_number;

 

    printf("Enter an integer \n");

    scanf("%d", &number);

    after_number = number << 2;

   

    printf("before Shift : %d \nAfter Shift : %d", number, after_number);

 

    if(after_number%4==0)

                printf("\nYes, Its Divisible by 4");

    else

                 printf("\nNo, Its notDivisible by 4");

   

}

Output:

Enter an integer

123

before Shift : 123

After Shift : 492

Yes, Its Divisible by 4

 


 Question 5:
Convert the following conversions:
B2O and B2H: 111100
D2B, D2O, and D2H: 819

Solution:

  



D2B: 819

Answer: 1100110011

D2O: 819

Answer: 1463

D2H: 819

Answer: 333

 



Comments

Popular posts from this blog

Flow Charts - What Is a Flow Chart? When to Use a Flowchart? Flowchart Symbols & Components

  Flow Charts     Flow charts are a useful tool in many situations, as we make a process easy to understand at a glance. Using just a few words and some simple symbols, they show clearly what happens at each stage and how this affects other decisions and actions.   What Is a Flow Chart?     In 1921, the Frank and Lillian presented what was only a "graphic-based method" in a presentation titled: “ Process Charts: First Steps in Finding the One Best Way to do Work ”, to members of the American Society of Mechanical Engineers (ASME). When to Use a Flowchart?     Flowchart is a very simple yet powerful tool to improve productivity in both our personal and work life. Here are some ways flowchart can be helpful:   ·      Document a process ·      Present solution to a problem ·      Brainstorm ideas in a meeting ·      Design an operation system ·    ...

Most Asked Pattern Programs in C

  Pattern Programs in C  

C++ Lec-2 Introduction to Object-Oriented Programming (OOP) in C++

  Introduction to Object-Oriented Programming (OOP) in C++ Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes to organize software design. It allows for modelling real-world entities and relationships in a program. C++ is an object-oriented programming language that provides features to implement OOP concepts effectively. Key Concepts of OOP   Class and Object o    Class : A blueprint for creating objects. It defines properties and behaviours of objects.   class Car { public:     string brand;     string model;     int year; };   o    Object : An instance of a class.   Car car1; car1.brand = "Mahindra"; car1.model = "THAR"; car1.year = 2024;   Encapsulation o    Encapsulation is the bundling of data and methods that operate on that data within a single unit, or class. It restricts direct acces...