Skip to main content

Zoho Interview | Set 3 QUESTION 1

Write a program to give the following output for the given input


Eg 1: Input: a1b10
       Output: abbbbbbbbbb
Eg: 2: Input: b3c6d15
          Output: bbbccccccddddddddddddddd
The number varies from 1 to 99.
 
 
 
MY SOLUTION ::
 
 
  
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

char s[10];


int i = 0;
int count,j;
int inc;
    scanf("%s",s);
    
while (1==sscanf(s+i, "%*[^0-9]%d%n", &count, &inc))
{
    
    for(j=0;j<count;j++)
        printf("%c",*(s+i));
    i += inc;
    count = 1;
}
    return 0;
}

Comments

  1. while (1==sscanf(s+i, "%*[^0-9]%d%n", &count, &inc))
    Can u explain this to me ??

    ReplyDelete
  2. The C library function int sscanf(const char *str, const char *format, ...) reads formatted input from a string.
    A format specifier follows this prototype: [=%[*][width][modifiers]type=]

    ReplyDelete
  3. can you explain the below line
    count =1
    without this line also it will work right?

    ReplyDelete
  4. can u plz xplain tis plz "%*[^0-9]%d%n"

    ReplyDelete
  5. can you explain this please "%*[^0-9]%d%n"

    ReplyDelete

Post a Comment

Popular posts from this blog

C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
{
int const * p=5; printf("%d",++(*p));
}
Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer: mmmm
aaaa nnnn
Explanation

Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
    1. Booking
    2. Availability checking
    3. Cancellation
    4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

 My Solution :

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>#include<iostream.h>#include<time.h>#include<iomanip.h>#include<fstream.h>char f[10]="f";char s[10]="s";int addr,ad,flag,f1,d,m,i,amt;float tamt; class login {public:char id[100];char pass[100];char*password;void getid(){ cout<<"Enter your id:";gets(id); password=getpass("Enter the password:");strcpy(pass,password);}void displayid(){ cout<<"Id:";puts(id); cout<<"Password:";puts(pass);}}; class detail {public:in…

Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as