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:
b. Logical operators:
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)
*
* *
* * *
* * * *
* * * * *
c program to display the following patterns(VVI)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
c program to display the following patterns(VVI)
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
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;
}
0 Comments