Palindrome
Palindrome
SAMPLE PROGRAMS
#include<stdio.h>
#include<string.h>
#define size 100
int main()
{
char temp1[size];
char temp2[size];
int i;
int j=0;
int k=0;
printf("\n Enter String:= ");
scanf("%s",temp1);
while(temp1[k++]!='\0');
k--;
for(i=k-1;i>=0;i--)
{
temp2[j]=temp1[i];
j++;
}
SORTING OF ARRAYS
The last parameter specifies whether to sort array in
ascending or descending order. The "greater than" symbol (>)
indicates an ascending sort; the "less than" symbol (<) indicates
a descending sort. If you do not specify the sorting order, then the
sort is ascending.
SAMPLE PROGRAMS
/* add.c -- Read a sequence of positive integers and print them
* out together with their sum. Use a Sentinel value
* (say 0) to determine when the sequence has terminated.
*/
#include <stdio.h>
#define SENTINEL 0
int main(void) {
int sum = 0; /* The sum of numbers already read */
int current; /* The number just read */
do {
printf("\nEnter an integer > ");
scanf("%d", ¤t);
if (current > SENTINEL)
sum = sum + current;
} while (current > SENTINEL);
printf("\nThe sum is %d\n", sum);
}
SAMPLE PROGRAMS
/* power2.c -- Print out powers of 2: 1, 2, 4, 8, .. up to 2^N
*/
#include <stdio.h>
#define N 16
int main(void) {
int n; /* The current exponent */
int val = 1; /* The current power of 2 */
printf("\t n \t 2^n\n");
printf("\t================\n");
for (n=0; n<=N; n++) {
printf("\t%3d \t %6d\n", n, val);
val = 2*val;
}
return 0;
}
/* It prints out :
n 2^n
================
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8192
14 16384
15 32768
16 65536
*/
RESEARCH
IN
D.S.A
#16
7:30-9:00am Lab
8:00-9:00am Lec