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

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...

C++ Lec-1 (Introduction to Programming Languages)

  Introduction to Programming Languages ________________________________________________________________________ P rogramming languages are formal languages comprising a set of instructions that produce various kinds of output. They are used in computer programming to implement algorithms and control the behavior of machines. Language Generation Programming languages have evolved through several generations: First Generation (1GL) : Machine language, the most basic level of programming languages, consisting of binary code. Second Generation (2GL) : Assembly language, a low-level language with a strong correspondence to the machine language instructions. Third Generation (3GL) : High-level languages like C, C++, Java, Python, which are more abstract and easier for humans to understand. Fourth Generation (4GL) : Languages closer to human language, often used for database querying and report generation (e.g., ...

DATA TYPE in C/C++

  BUILT IN OF PRIMARY DATA TYPE     int (Integer) float(Floating-point) double (Double Floating-point) char (Character) wchar_t (Wide Character) bool (Boolean) void (Empty) Modified Data Types List    signed int - (used for integers) unsigned - int (can only store positive integers) short (used - for small integers (range -32768 to 32767)) unsigned short - (used for small positive integers (range 0 to 65,535)) Long - (used for large integers) unsigned long - (used for large positive integers ) long long - (used for very large integers) unsigned long long - (used for very large positive integers) long double - (used for large floating-point numbers) signed char - (used for characters (guaranteed range -127 to 127)) unsigned char - (used for characters (range 0 to 255)) Derived Type Data Type    Function Array Pointers References User-Defined Data Type   Class Structure Union Enumeration Typedef defined DataType