Skip to main content

Posts

Showing posts from December, 2014

Program to find sum of first 1000 Primes Numbers

#include <stdio.h> int main (int argc,char *argv[]) {         int i,j,sum = 0,range = 1000;         int flag = 0,count = 0;         for (i = 2 ;count < 1000;i++) {                 //check for prime                 for (j = 2; j < i ;j++) {                         if (i % j == 0) {                                 flag = 1;break;                       ...

Program for Largest Prime Palindrome (1 - 1000)

/* Program to print largest prime palindrome with range (1-1000)     Problem - https://www.codeeval.com/open_challenges/3/ */ #include <iostream> using namespace std; int main() {         int num,i,j,digit = 0,rev = 0;         int flag = 0;         for (i = 1000;i >= 2;i--) {                 flag = 0,rev = 0;                 //check for prime                 for ( j =2; j < i /2;j++) {                         if ( i % j == 0) {              ...

Solution Program for Fizz Buzz Problem

#include <stdio.h> #include <stdlib.h>   /*   * Solution Program for FizzBuzz (codeeval.com) - https://www.codeeval.com/open_challenges/1/   */ int main(int argc,char *argv[]) {         FILE *fp;         int x,y,count,i;         if (argc < 2) {          printf("Error :- File not specified \n");          exit(0);         }         fp = fopen (argv[1],"r");         if (fp == NULL) {                 printf("Error :- Can't open file \n");                 exit(0);         } ...

Program to print a non repeated character in string

#include<stdio.h> #include<string.h> /* Program to print a non repeated character in string  *  */ int main() {         int count[256] = {0}; /* count of the characters */         char string[20];         int i;         printf("Enter the string \n");         scanf("%s",string);         for (i = 0;i < strlen(string)-1;i++) {                 count[*(string+i)]++;   /* increments the count based on ASCII Range */         }         for (i = 0;i < strlen(string)-1;i++) {                 if (count[*(string+i)]== ...