C++ :: Find The Highest Digit Within C-String
Oct 27, 2014
I can't find the highest digit within c-string. Ithe user was to enter 1234. the highest shall be 4 but can't get that number.
int Hnum(char* str) {
//int size = 0;
int H = 0, remainder, div =0;
int intstr = atoi(str);
[Code] ....
View 2 Replies
ADVERTISEMENT
May 17, 2014
The code shows all characters frequency, however i want to find which one has highest frequency
For example cprogrammmmming cboard
highest frequency: m
Code:
char string[100], ch;int c =0, count[26]={0};
printf("Enter a string
");
gets(string);
[Code] ....
View 3 Replies
View Related
Dec 23, 2013
I have this example problem in my school coursebook. How this program works? It determines the highest digit in a number.
#include <iostream>
using namespace std;
int m(int n) {
int a,b;
[Code] ....
View 4 Replies
View Related
Aug 25, 2013
if i have two integers, say number1 and number2, stored in arrays where each index is a digit of the number (i.e. if my numbers are 321 and 158, then number1 = {3,2,1} and number2 = {1,5,8}), can i find the remainder of number1/number2? assume number1 > number2.
View 1 Replies
View Related
Nov 4, 2013
I am currently trying to make a simple method for an array that would find the highest value. here is currently what i got, but do not know what to change to make it correct.
double FindMax(double stock[], int size){
int size = stock.length();
int max = stock[0];
for(int i = 1; i < size; i++){
if (stock[i] > max)
{max = stock{i};}
}
return max;
View 3 Replies
View Related
Jan 24, 2015
Given an integer, find the sum of all the digits in the number until the sum becomes a single digit. E.g. sum of digits of 9264 = 21. Then sum of 21 = 3.
View 2 Replies
View Related
Sep 29, 2013
How can I properly find the lowest and the highest temperatures?
#include <iostream>
#include <string>
using namespace std;
[Code]....
View 1 Replies
View Related
Jun 6, 2013
I have reduced it for lower numbers but for some reason with higher numbers when i get the program to out put all the primes they are in minuses!!!
I need a way to make this even faster, or maybe theres a better mathematical answer, I know that for numbers in their 1,000,000,000,000 have an average of 1 prime every 26.6 numbers (i think thats right there is 37,607,912,018 primes in the number 1,000,000,000,000) is there anyway i can utilize this??
#include <iostream>
using namespace std;
int main() {
int primeanswer = 1,p = 1;
for (int i=1;i<35; i++)
[Code] .....
View 19 Replies
View Related
Aug 13, 2014
How do I compare multiple datas?
I have climate data for 6 months and is trying to find the highest climate month among all 6 months. How do I do that?
View 2 Replies
View Related
Oct 9, 2014
Create a 1-D Array to hold a set of exam scores:
55 74 93 84 64 72 69 78 87 84 72 33 83 68 62 51 88 90
Write a program to do the following tasks:
1. Display scores in rows of four(4) scores.
2. Calculate average score and display.
3. Find Lowest score and display.
4. Find Highest score and display.
5. Find the deviation of each score, and display the score and its deviation.
6. Find the Standard Deviation and Display
7. How many scores are within One Standard Deviation
So I have the average down, but I am getting stuck at the part of displaying the highest and lowest score. Every time I run the program I get two giant negative numbers for both of them. I put all the scores into a .txt file and I just opened in through the program.
#include "TCHAR.h"
#include <iostream>
#include <fstream>
#include <iomanip>
[Code]....
View 1 Replies
View Related
Jun 6, 2014
I have a question regarding finding similar 4 digit numbers in a pool of 120 numbers
Below is an linear single dimension array of 4 digits
There are 120, 4 digit numbers in total
My question is this - How can I code in C - a function that looks through all the 120, 4 digits to find similar numbers
Example - 2095 is similar or matches to - 0950, 5095, 5250, 5269 - i.e having 3 of the digits that are the same in the 4
The code must print out 2095 + all the matched numbers
If the Matched or Similar numbers are less then a certain number n - that number is discarded and the code should go onto the next number
2095095053741884864037233464846523768035
4340520865405306753553226100610753235081
1160346508409698809176715645765520676974
2398509523307591808464215318649140982136
2388015030217584311064844010520796345135
5376565155806436092330366745536969232311
4351519149310340620918615194324744655250
5330634052450976531053882380318069765623
2186677440212394367468519636617536556706
5274239549814534091052060118499521655275
6351091153944834003545212360098053955218
4835406061305276769161885611376776845269
I have written some code below but it is not working ...
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <memory.h>
#include <dos.h>
FILE *fileptr;
FILE *fileptr1;
[Code] ....
View 10 Replies
View Related
Aug 10, 2014
We will make it in Turbo C, C++ and VB.. but as of now (Turbo C and C++)
This is the problem
Make a program based on the given logic below
a>b && a>c - a highest
b>a && b>c - b highest
c>a && c>b - c highest
and will determined the lowest
we will do this in different program control statements:
1.If-Then-Else
2.Multiple-If
3.Nested-If
4.Do Case
5.Do While
6.Do Until
7.For Next
8.Switch
9.Break
10.Loop
is it possible?
View 1 Replies
View Related
Jan 3, 2014
I have a list of numbers with decimal point saved in a text file (grade.txt) like this:
80.2
85.7
57.2
90.0
92.9
74.0
76.5
...
I would like to write a small program to display the top 10 highest and lowest grade points.
View 3 Replies
View Related
May 17, 2014
the code shows all characters frequency, however i want to find which one has highest frequency for example cprogrammmmming cboard highest frequency: m
char string[100], ch;int c =0, count[26]={0};
printf("Enter a string");
gets(string);
[Code].....
View 8 Replies
View Related
Oct 26, 2014
Write a function which will take 3 arguments. The function needs to return a new number which is formed by replacing the digit on a given position in the number with a digit which is carried as an argument (the position in the number is counted from right to left, starting with one). Write a main program which will print the newly formed number.
Examples:
A function call of 2376, 3 and 5 should return the number 2576
A function call of 123456, 4 and 9 should return the number 129456
What I succeeded to do so far:
Figure out the logic for swapping the digit and write working code for it (in the main function).
What I failed to do so far:
Write a function which will return the desired result.
What is my problem:
I tried writing a function to do this, but as you see from my calculations, my result is divided in 3 parts. I don't know how to return more variables from a function.
Code:
#include <stdio.h>
int main() {
int inputNumber, swapPosition, swapDigit;
scanf("%d%d%d", &inputNumber, &swapPosition, &swapDigit);
int i, numberPart1 = inputNumber;
for (i = 1; i <= swapPosition; i++)
[Code] ...
View 8 Replies
View Related
Oct 23, 2014
bool isQstr(string const& str)
{
size_t found = str.find(""");
return found != string::npos;
}
/*
I am trying to check whether a string contains a quoted string, I used the escape character but it does not even recognize it*/
View 1 Replies
View Related
Aug 25, 2013
I know how to find find ASCII value of given character, but I am not getting how to find ASCII value of given string. For example I want to find ASCII value of string "HELLO",so how to do that.
View 13 Replies
View Related
Oct 15, 2013
So the program reads contents from a text file into a vector and then the user enters in a string that they want to search for. The program iterates through the vector to find the string and then saves that line to another vector to display later(incase there is more then 1 instance of the string found).
Here is what I have atm:
void doSearch(vector<string> &phonelist, string searcher, vector<string> &holdNumbers)
{
int i = 0;
string value;
[Code].....
I just get an R6010 error -abort() has been called.
View 2 Replies
View Related
Jul 6, 2014
int t;
string a;
cin>>t;
getline(cin,a);
int len=a.length();
cout<<a<<" "<<len;
[code].....
why is the length 0?what can I do to get the correct length of the input string?
View 5 Replies
View Related
Dec 15, 2014
I am stuck here.
printf(" Enter a line of Morse Code for decrypting");
scanf("%s",phr);
len=strlen(phr);
for(a=0;a<36;a++) {
if(strcmp(phr, morse[a])==0)
printf("%c", alpha[a]);
};printf(" ");
The output :
[output] Enter line to encrypt:
..... -.... --...
converting...
5 [/output]
It should read all code, including null. between coded letter one space, between coded word three spaces.
The output should be:
[output]
56 7 [/output]
View 9 Replies
View Related
Apr 23, 2012
I am stuck in some logic and want to write a program to do following tasks : I have three string variables to be compared to each other,a string having sub string & hierarchy string!!
1.) name1=john name2=tom_john_tom name3=alextom_john
thus we need to search john from name2 and name3 and if name1 exists in both name2 and name3 then ok else check for step2
2.) name1=a.b.c.d ,name2=a.b.c.d and name3=a.b.c.d
we need to compare each string seperated by a dot in all three variables and we need to match each string seperated by a delimeter "."
if name1.a==name2.a==name3.a and name1.b==name2.b==name3.b ,name1.c==name2.c==name3.c and name1.d==name2.d==name3.d then its a match
else its a mismatch
Also,the catch is we can have name1 ,name2 and name3 in format name1=*.*.*.* and name2=*.*.*.* and name3=*.*.*.*
where * defines it can be any value to be matched
name1=government.india.public.property
name2=rural.roads.maximum.x
name3=government.india.public.sales
name4=rural.roads.minumum.x
If operator wants to match only the second field , then the logic should be like:
If the Value is to be matched = (*.#.*.*)
then "matched"
Else
its a mismacth
# => for this field of name2 and name3 shall be same
* => for this field name2 and name3 shall be ignored for comparison
to obtain option1 we can have find function and substr however pls suggest how to approach for second option !!!!
View 1 Replies
View Related
Jan 26, 2015
I got a homework that require to count number of words in a text file and also display the first and last 10 words of the text file to the console. I have finished the counter problem and now I struggle showing the first and last 10 words.
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int tokenize(string sentence, string tokenizedWords[]);
[code]....
View 2 Replies
View Related
Jan 11, 2013
I need to find position of certain character in string, so i made a function but it doesn't do what i thought it would.
Consider this string:
std::string line = "<foo> <foo> <foo> <foo> <foo>"
I need to find position of a third '>' character so i can get:
std::string other = "<foo> <foo> <foo>";
This is my function that fails:
std::size_t find_third(const std::string& line) {
std::size_t pos = 0u;
for(std::size_t i = 0; i < 3u; ++i) {
std::string tmp = line.substr(pos);
pos = tmp.find_first_of('>');
} return pos;
}
View 6 Replies
View Related
Sep 25, 2014
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void findPalind(char *arr) {
int i,j,n,odd,flag=0,count[26]={0};
[Code] ....
This question was asked in Hackerrank. [URL] ....
I am able to get correct output upto a input of 50000 character string, but not for 100000 character string.
View 12 Replies
View Related
Apr 29, 2015
How to find the last longest word in a string when there are more of them (with the longest size)?
Here is the program for the longest without checking if last:
#include<stdio.h>
#include<string.h>
int main() {
char a[50],b[20],c[20];
int i,j=0,l=0;
printf("Enter a string:
");
gets(a);
[Code] ....
View 6 Replies
View Related
Feb 3, 2013
i have a text file... with example following content:
Pizza 23232
Car 44,495
Drink 3493,90494
....
..
.
and so on..
no i want to find the 44,495 in this textfile.. calculate a new value like 44,495 x 2 + 5
and write the same file as
Pizza 23232
Car 93,99
Drink 3493,90494
....
..
.
back..
View 2 Replies
View Related