Very important question of BICTE of Programming Concept C

 

Very important question of BICTE | Programming Concept C | Study Material/

 Previous year question solution

Relational and logical operators:

All the relational, equality and logical operators are binary except !(not) and they take two operands and yield either int value 1 or int value 0.

a.     Relational operators:

Relational operators are used in computer programming to compare two values and determine the relationship between them. They are called "relational" operators because they determine the relationship or ordering between two values. The most common relational operators are:

  • Equality operator (==): returns true if two values are equal.
  • Inequality operator (!=): returns true if two values are not equal.
  • Greater than operator (>): returns true if the left operand is greater than the right operand.
  • Less than operator (<): returns true if the left operand is less than the right operand.
  • Greater than or equal to operator (>=): returns true if the left operand is greater than or equal to the right operand.
  • Less than or equal to operator (<=): returns true if the left operand is less than or equal to the right operand.

For example, if x = 5 and y = 10, then:

  • x == y returns false
  • x != y returns true
  • x > y returns false
  • x < y returns true
  • x >= y returns false
  • x <= y returns true

Relational operators are often used in conditional statements and loops to make decisions based on the relationship between two values.

b.     Logical operators:

Logical operators are used in computer programming to combine multiple conditions and determine if a certain condition is true or false. They allow you to create complex expressions that can be evaluated to a single Boolean value. The three most common logical operators are:

  • AND operator (&&): returns true if both conditions are true, otherwise false.
  • OR operator (||): returns true if at least one of the conditions is true, otherwise false.
  • NOT operator (!): returns the opposite value of the condition, true becomes false and vice versa.

For example, if x = 5 and y = 10, then:

  • (x < 10 && y > 5) returns true, because both conditions are true.
  • (x > 10 || y < 5) returns false, because neither condition is true.
  • !(x == 5) returns false, because x is equal to 5 and the NOT operator changes it to false.

Logical operators are often used in conditional statements to check multiple conditions at once. They are also useful when working with Boolean values and logic operations.

1.      C program to find factorial of number. VVI

/* C Program to Find Factorial of a Number */

 

#include <stdio.h>

 

int main()

{

  int i, n, fact=1;

  printf("\n Enter any number to Find Factorial\n");

  scanf("%d", &n);

 

  for (i = 1; i <= n; i++)

   {

     fact = fact * i;

   }

 

  printf("\nFactorial of %d = %d\n", n, fact);

 

  return 0;

}

Rough:

N =5

5*4*3*2*1=120

I=1, 1<=5,true

Fact=1*1=1

I=2, 2<=5,true

Fact=1*2=2

I=3, 3<=5,true

Fact=2*3=6

I=4, 4<=5,true

Fact=6*4=24

I=5, 5<=5

Fact=24*5=120

I=6, 6<=5

False

 

 

 

 

 

2.      C program to reverse a number. VVV

/* C Program to reverse a number */

#include <stdio.h>

int main() {

    int n, rev = 0, r;

    printf("Enter a number: ");

    scanf("%d", &n);

    while (n != 0) {

        r = n % 10;

        rev = rev * 10 + r;

        n = n/10;

    }

    printf("Reversed number = %d", rev);

    return 0;

}

Rough:

N =123

Step1:

        r = 123 % 10;

        r=3

        rev = 0 * 10 + 3;

        rev=3

        n = 12/10;

        n =12

        r = 12 % 10;

        r=2

        rev = 3* 10 + 2;

        rev=32

        n = 1/10;

        r =1%10;

        r=1

        rev=32*10+1

        rev=321

        num=0/10

 

 

 

 

 

 

3.      C program to palindrome a number. VVVI

/* C Program to check whether a number is palindrome or not */

#include <stdio.h>

int main() {

    int n, rev = 0, r, temp;

    printf("Enter an integer number: ");

    scanf("%d", &n);

    temp = n;

 

    // reversed integer is stored in rev

    while (n != 0) {

        r = n % 10;

        r = r * 10 + r;

        n =n/ 10;

    }

 

    // palindrome if temp and rev are equal

    if (temp == rev)

        printf("%d is a palindrome.", temp);

    else

        printf("%d is not a palindrome.", temp);

 

    return 0;

}

 c program to display the following patterns(VVI)

*

*  *

*  *  *

*  *  *  *

*  *  *  *  *

#include<stdio.h>
int main()
{
    int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("*");
        }
        printf("/n");
    }
    return 0;
}

 

 c program to display the following patterns(VVI)

1

1  2

1  2  3

1  2  3  4

1  2  3  4  5


#include<stdio.h>
void main()
{
  int i,j;
  for(i=1;i<=5;i++)
  {
    for(j=1;j<=i;j++)
    {
        printf("%d",j);
    }
    printf("\n);
  }


}


}

 

 c program to display the following patterns(VVI)

1

2  2

3  3 3

4  4  4  4

5  5  5  5  5

 

#include<stdio.h>
void main()
{
  int i,j;
  for(i=1;i<=5;i++)
  {
    for(j=1;j<=i;j++)
    {
        printf("%d",i);
    }
    printf("\n);
  }


}


}

 

 

 

 

 

 

4.      C program to display Fibonacci series.VVI

/* C Program to display Fibonacci series */

#include <stdio.h>

int main() {

    int i, n, t1 = 0, t2 = 1;

    int nextTerm = t1 + t2;

    printf("Enter the number of terms: ");

    scanf("%d", &n);

    printf("Fibonacci Series: %d, %d, ", t1, t2);

 

    for (i = 1; i <= n; ++i) {

        printf("%d, ", nextTerm);

        t1 = t2;

        t2 = nextTerm;

        nextTerm = t1 + t2;

    }

 

    return 0;

}

Post a Comment

0 Comments