DAY 1- DATA TYPE ON HACKER RANK
TASK--> Three variable i, d and s are already declared and initialized for you, you must.
1. Declare 3 variable : One of type int, one of type double, one of type string.
2. Read 3 line of input from stdin and intilized your 3 variable.
3. Use + operator to perform following operation.
a.) Print sum of i plus your int variable on a new line.
b.) Print sum of d Plus your double variable on a new line.
c.) Concatenate S with the String you need as input & print the result on a new line.
/*PROGRAM START FROM HERE -->*/
/* #include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int main(){
int i=4;
double d=4.0;
char S[] = "HackerRank"; */
#define MAX_BUFFER 255
// declare 2nd integer, double, & String variable
int si;
double dd;
char *buff = malloc (MAX_BUFFER);
if(buff = NULL){
printf("Memory Error \n");
return 1;
}
//read and save an integer, double & structure to your variable.
if(fgets(buff, MAX_BUFFER, stdin)!= NULL){
sscanf(buff, "%d", &si);
printf("%d \n", i+si);
}
if(fgets(buff, MAX_BUFFER, stdin)!= NULL){
sscanf(buff, "%lf", &dd);
printf("%d \n", d+dd);
}
if(fgets(buff, MAX_BUFFER, stdin)!= NULL){
sscanf(buff, "%%S", &dd);
printf("%s %s \n", s , buff);
}
return 0;
/*
int i1;
double d1;
char str[200];
scanf("%d", &i1);
scanf("lf", &d1);
scanf("[^\n]%*c", str);
printf("%d \n", i+i1);
printf("%0.1lf \n", d +d1);
pritnf("%s", s); //j error here
*/
Comments
Post a Comment