Skip to content

Instantly share code, notes, and snippets.

@manuj10
Last active December 17, 2015 23:59
Show Gist options
  • Save manuj10/5693671 to your computer and use it in GitHub Desktop.
Save manuj10/5693671 to your computer and use it in GitHub Desktop.
Gist containing solution to two problems: a)Write a function (in any language) which takes 'n' as an argument and prints all the numbers from 1 to 'n', except that: (a) if a number is divisible by 3, it should print 'Hip' instead of the number, (b) if divisible by 5 it should print 'Hop', and (c) if divisible by 3 & 5, it should print 'Whazaa' i…
//snippet for generating random numbers for input.txt :https://gist.github.com/manuj10/5701051
//sol for part b.
#include<stdio.h>
#include<conio.h>
int main()
{FILE *filepointer;
filepointer=fopen("input.txt","r");
static int i=0,freq[5000],j=0,max=0;
while(!feof(filepointer))
{
fscanf(filepointer,"%d",&i);
freq[i]++;
if(i>=max)
max=i;
}
printf("number-->frequency\n");
for(j=0;j<=max;j++)
{printf("%d------->%d\n",j,freq[j]);}
getch();
return 0;}
//solution for part a
#include<stdio.h>
#include<conio.h>
int main()
{int input,i;
printf("Enter the number\n");
scanf("%d",&input);
for(i=1;i<=input;i++)
{if((i%3||i%5)==0)
printf("Whazaa\n");
else if(i%3==0)
printf("Hip\n");
else if(i%5==0)
printf("Hop\n");
else
printf("%d\n",i);}
getch();
return 0;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment