Académique Documents
Professionnel Documents
Culture Documents
Algorithm:
ASCII value of 'A' is 65 while 'a' is 97. Difference
between them is 97 65 = 32
So if we will add 32 in the ASCII value of 'A' then it
will be 'a' and if will we subtract 32 in ASCII value of
'a' it will be 'A'. It is true for all alphabets.
In general rule:
Upper case character = Lower case character 32
Lower case character = Upper case character + 32
Algorithm:
ASCII value of 'A' is 65 while 'a' is 97. Difference
between them is 97 65 = 32
So if we will add 32 in the ASCII value of 'A' then it
will be 'a' and if will we subtract 32 in ASCII value of
'a' it will be 'A'. It is true for all alphabets.
In general rule:
reverse
return 0;
}
Sample output:
Enter any string : cquestionbank.blogspot.com
Reverse of string is : moc.topsgolb.knabnoitseuqc
Reverse a string in c using pointers
C program to reverse a string using pointers
#include<stdio.h>
int main()
{
char str[50];
char rev[50];
char *sptr = str;
char *rptr = rev;
int i=-1;
printf("Enter any string : ");
scanf("%s",str);
while(*sptr)
{
sptr++;
i++;
}
while(i>=0)
{
sptr--;
*rptr = *sptr;
rptr++;
--i;
}
*rptr='\0';
printf("Reverse of string is : %s",rev);
return 0;
}
Sample output:
Enter any string : Pointer
Reverse of string is : retnioP
#include<string.h>
#include<stdio.h>
int main()
{
char *str,*rev;
int i,j;
printf("\nEnter a string:");
scanf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe string is not a palindrome");
else
printf("\nThe string is a palindrome");
return 0;
}
int k,n;
long int i=0,j=1,f;
printf("Enter the range of the Fibonacci series:");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",0,1);
printFibonacci(n);
}
void printFibonacci(int n)
{
static long int first=0,second=1,sum;
if(n>0)
{
sum = first + second;
first = second;
second = sum;
printf("%ld ",sum);
printFibonacci(n-1);
}
}
Sample output:
Enter the range of the Fibonacci series: 10
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 55 89
Sample output:
Enter any two integers: 5 10
Sum of two integers: 15
Algorithm:
In c ~ is 1's complement operator. This is equivalent to:
~a = -b
So, a = a-(-b
= a + b
= a + b
+ 1
~b -1
+ 1) + 1
1 + 1
subtract
two
#include<stdio.h>
int main()
{
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a + ~b + 1;
printf("Difference of two integers: %d",sum);
return 0;
}
Sample Output:
Enter any two integers: 5 4
Difference of two integers: 1
numbers
#include<stdio.h>
int main()
{
int num = 1;
print(num);
return 0;
}
int print(num){
if(num<=100)
{
printf("%d ",num);
print(num+1);
}
}
Output:
Sample output:
1 2 3 4 5 6 7 8 9
23 24 25 26 27 28
42 43 44 45 46 47
61 62 63 64 65 66
80 81 82 83 84 85
99 100
10
29
48
67
86
11
30
49
68
87
12
31
50
69
88
13
32
51
70
89
14
33
52
71
90
15
34
53
72
91
16
35
54
73
92
17
36
55
74
93
18
37
56
75
94
19
38
57
76
95
20
39
58
77
96
21
40
59
78
97
22
41
60
79
98
= (0+1) , (1+0)
=1,1
2 row = (0+1) , (1+1) , (1+0)
=1,2,1
3 row = (0+1), (1+2), (2+1), (1+0)
=1,3,3,1
4 row = (0+1), (1+3) , (3+3), (3+1), (1+0)
= 1,4,6,4,1
#include<stdio.h>
long fact(int);
int main()
{
int line,i,j;
printf("Enter the no. of lines: ");
scanf("%d",&line);
for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");
for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");
}
return 0;
}
long fact(int num)
{
long f=1;
int i=1;
while(i<=num){
f=f*i;
i++;
}
return f;
}
Sample output:
Enter the no. of lines: 8
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1