Tags:C Interview Question, C++ Questions | 94 views
#include <stdio.h>
void dec2bin(long decimal, char *binary);
int main()
{
long decimal;
char binary[80];
printf(”\n\n Enter an integer value : “);
scanf(”%ld”,&decimal);
dec2bin(decimal,binary);
printf(”\n The binary value of %ld is %s \n”,decimal,binary);
Tags:C Interview Question, C++ Questions | 74 views
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char string[100];
int i,found=0;
printf(”Type a string : “);
gets(string);
for(i=0;i<strlen(string);i++)
if( isalpha(string[i]))
found++;
printf(”Number of characters: %d\n”,found);
return 0;
without using functions
#include<stdio.h>
#include<string.h>
void main()
{
char string[80];
char *s;
int <strong class=”highlight”>count</strong>=0;
int len;
printf(”Enter string\n”);
gets(string);
len=strlen(string);
printf(”%d”,len);
for(s=string;*s!=’\0′;s++)
{
if(*s==’ ‘)
{
count++;
}
else
break;
}
printf(”Number of words in string %d”,count);
}
[...]
Tags:C Interview Question, C++ Questions | 84 views
Here’s a simple function that does an infinite loop. It prints a line and calls itself, which again prints a line and calls itself again, and this continues until the stack overflows and the program crashes. A function calling itself is called recursion, and normally you will have a conditional that would stop the [...]
Tags:C Interview Question, C++ Questions | 85 views
Branching is performed using jump statements, which cause an immediate transfer of the program control. The following keywords are used in jump statements:
· The break Statement
· The continue Statement
· The return Statement
· The goto Statement