Old is gold solution of programming in c | 2075 set B

Old is gold solution of programming in c | 2075 set B

2075 set B Q.No 1a

What is operator? Explain logical and relational operator

Operator is a symbol that helps to perform certain mathematical operations or logical manipulation. Operators in C are used to operate on data and variables. C has a rich number of operators.

Logical operator

Logical operator in C program is used to give logical value either true or false. Logical operator compare or evaluate logical and relational expression.

Operators

Meaning

Example

&&

Logical AND

(a>b)&&(a>c)

||

Logical OR

(a>b)||(a>c)

!

Logical NOT

!(a==b)

 

Relation operator

Relation operator compares the relation between operands and find the decision respectively. The relation operators are used to compare any two-variable or expression so it is also called a comparison operator. Logical operators used in the C program is given as below

Operator

Meaning

Example

< 

First expression is less than second expression

a<b

<=

First expression is less than or equal to second expression

a<=b

> 

First expression is greater than second expression

a>b

>=

First expression is greater than or equal to second expression

a>=b

==

Both expression are equal

a==b

!=

First expression are not equal to second expression

a!=b

 

2075 set B Q.No 1b

Write a C program to find out whether entered number is positive or negative

#include<stdio.h>

#include<conio.h>

void main()

{

          int n;

          printf("\n Enter a number");

          scanf("%d", &n);

          if(n>0)

          {

                   printf("\n %d is positive number",n);

          }

          else

          {

                   printf("\n %d is negative number",n);

          }

          getch();

}

Output



2075 set B Q.No 2b

Write a C program to enter 5 integer numbers into an array and display.

#include<stdio.h>

#include<conio.h>

void main()

{

          int num[5], i;

          printf("\n Enter 5 number");

          for(i=0;i<5;i++)

          {

                   scanf("%d", &num[i]);

          }

          for(i=0;i<5;i++)

          {

                   printf("\n %d", num[i]);

          }

          getch();

}

Output



2075 set B Q.No 3

What is function? Write a C program to read the principle, time and rate. Find the simple interest using a function.

#include<stdio.h>

#include<conio.h>

void si(int, int, int);

void main()

{

          int p, t, r;

          printf("\n Enter principle, time and rate");

          scanf("%d%d%d", &p, &t, &r);

          si(p,t,r);

          getch();

}

void si(int p, int t, int r)

{

          int s;

          s=(p*t*r)/100;

          printf("\n Simple interest=%d",s);

}

Output



2075 set B Q.No 4

Write a C program to store 50 records of students using fields, std. no, name, and mark. Display the name of student and mark

#include<stdio.h>

#include<conio.h>

void main()

{

          struct record

          {

          int roll, mark;

          char name[30];

    };

    struct record a[50];

    int i;

          printf("\n Enter std no.,Name and mark of 10 students");

          for(i=0;i<50;i++)

          {

                   scanf("%d%s%d", &a[i].roll, a[i].name, &a[i].mark);

          }

          for(i=0;i<50;i++)

          {

                   printf("\n Name=%s\t mark:=%d", a[i].name, a[i].mark);

          }

          getch();

}

Output



We just take input of 10 students because of taking records of 50 students goes output long and it is not possible to capture.

Post a Comment

0 Comments