Q.12 Write a C program which reverses the digits of the integer input given to it. For example an input 65367 is outputted as 76356. (AKTU. 2009-10)
Related Questions -
Q. Write a function in C that finds the reverse of a “ given integer number. (AKTU. 2010 - 11)
Ans.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 30
char string[size];
void main()
{
int length;
clrscr();
printf("\nEnter the number\n");
gets(string);
length = strlen(string);
printf("\n The reverse of the number is:");
while(length >= 0)
printf("%c",string[length--]);
getch();
}
Q.13 Write a C program to arrange given n strings in lexicographical order. (AKTU. 2009-10)
Related Questions -
Q. Write a program in C to sort the given list of names. (AKTU. 2009-10)
Ans.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define n 5
int sort_function( const void *a, const void *b);
char list[n][4] = { "cat", "car", "cab", "cap", "can" };
int main(void)
{
int x;
clrscr();
qsort((void *)list, n, sizeof(list[0]), sort_function);
for (x = 0; x < n; x++)
printf("%s\n", list[x]);
getch() ;
return 0;
}
int sort_function( const void *a, const void *b)
{
return( strcmp((char *)a,(char *)b) );
}
Q.14 Write a program in C that reads the two strings of length at least 7, then concatenate these strings. (AKTU. 2010 - 11)
Ans.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 10
void main()
{
char str1[size], str2[size], res[2 * size];
clrscr();
printf("\n Enter first string");
gets(str1);
printf("\n Enter second string");
gets(str2);
strcat(res, str1);
strcat(res, str2);
printf("\n The concatenation of string is:\n");
printf("%s", res);
getch();
}