I want to have a program that will calculate the sum of the fourth powers of 100 real numbers in an array (numbers in this array are stated explicitly in the code), code I have for integers is working perfectly but i want it to work also for non integers.
Code:
#include "stdafx.h"
#include "math.h"
int sum_array(int a[], int numelements) {
long double i, sum = 0;
for (i = 0; i<numelements; i++) {
sum = sum + pow((float)a[i], (int)4);
[code]....
The error messages i have: return' : conversion from 'long double' to 'int', possible loss of data.
As I am taking my first steps in C, I study K&R (I guess most of you did the same, right?)
In the introductory chapter about functions (1.7) there is an example showing how to create a function that is then called to calculate powers (b**n). I simplified it to calculate only one given power, 2**5:
Code:
#include <stdio.h> int power(int m, int n); main() { printf("%d", power(2,5));
[Code]....
It will then be called to make the calculation in the above string.
First things first: we already know how to use while(getchar!=EOF) to count characters (K&R chapter 1.5.2) but what if -instead- the input is a specific string? How to "read" it and how to tell my program that the string is finished? And most important: "reading" will be done in the function or in the rest of the body?
Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.
I'm stuck on how to put the prime numbers into an array.
The input file has the numbers 1 & 100.
Here's what I have so far.
#include <iostream> #include <fstream> using namespace std; int main() { ifstream fin; fin.open("numbers.txt");
The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14. I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:
#include <iostream> #include<fstream> int decryption(int); int multiply(int,int[][2]); using namespace std; main(){ int n; ifstream inFile; inFile.open ("out.txt");
[Code] .....
I was trying to store numbers read from a text file into 2D array but I am getting the error above.here is where the error occurs:
iam trying to count the same numbers in an array just once like
38 38 40 38 40 37
the output should be 2 since 38 is repeated and 40 too but for my code the output is 3 thats an example of how it should be in a nutshell i want same number to be counted just once in the whole array
and here's my code :
#include <iostream> using namespace std; int main(){
I am unable to create an array which has to content elements(1E, 2E, 3E, 4E). I tried using char however I am unable to display as it only shows the letter E.
I was trying to make a program that asks the number of grades, get the grades and then get the average. I know I have to save the grades in an array but i don't know exactly how.
So i have this program that takes in user input and stores them into an array and then prints them, removes duplicates, and sorts in ascending order. The user can also stop by inputting a sentinel value (in this case -1). But i am also supposed to ignore any negative value besides -1. When i input any other negative value into the program it messes up. How would i go about ignoring the negative values?
Code: #include<stdio.h> int main() { int input, nums[20], i, j, k, temp, count=0, count2=0; for(i=0;i<20;i++)
I wrote some code for class to find prime numbers.The teacher says that I need to revise my code with the requirement below: use a bit array to store the prime number checking. The bit array will also be in the heap. Use the max value of an unsigned 32-bt integer (UINT_MAX) to be the maximum size of the prime number you want to check.
I want to write a programm that will reverse the order of the numbers in an array (e.g. as an input 1,2,3.5,4 and as an output i want 4,3.5,2,1) . But i have to problems:
1) I do not know how to properly change the type of a numbers inside an array from int to float or double, changing int to float in front of the a[10], does not change anything instead the code does not want to compile then.
2) I also want to make an array of a number of elements typed by a user with use of a "do" loop and how to put this parameter in the code.
Here is my code:
Code:
// ConsoleApplication3.cpp : Defines the entry point for the console application.// #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int a[10], i, n; int pom; do { printf("number of elements in an array a: n = ");
How to assign numbers stored in a buffer memory to a 2D array.
The data type is unsigned 16bit (unsigned short) integers and they are stored in a 16bit/2bytes*1280*1024=2621440 bytes memory. The pointer pBuffer is the starting address of the buffer. Now I initiated an array and then assign the numbers to the array.
So I already gave this a go and will post my code below. The question is about the last loop before the program cout's. i thought the count would keep track of the repeated numbers so i could display them but it does not. I italicized the loop i am referring to. or at least i tried to xD
#include <iostream> #include <iomanip> using namespace std; int main() { int inputs[30]; int numofloops; int maxvalue = inputs[0];
I am trying to find a way to do something like this:
input: 3 4 7 4 3 3 7 output: 3 4 7
So what I am trying to do is from an array of integers to take numbers that occur only once. If 3 is in that away I am trying to input it in a different array only once.
input: 8 3 2 9 8 9 2 output: 2 3 8 9
I cannot find a way to solve this, and I have been trying to solve it for a long time.
I want to accept numbers from the user into an array and convert into corresponding alphabets. E.g 1 into A, 2 into B, and so on.
This is simple, but the problem is the user is supposed to enter the character # also which I want to display as it is in the output. How can I do this ? What type of array should be used - int or char?
I want to make an array with a range of number from 1-9 only. So if the user entered more than or less than the number indicated it will be error and ask the user to reinput the data. So far my code can be used to do so that if the user enter the number one by one... But if the user entered all the number in one shot the reentered value will be prompt to the back automatically for some reason...Let say 10,2,3,4 which was suppose to be 1,2,3,4 became 2,3,4,1 instead... here is the code:
#include<stdio.h> void main() { int num[4][4]; int row,col,x,y; for(row=0;row<4;row++)