dear all
i want and as fast as possible a working C program for the following problem.
i have an array values[ ] consisting of 'n' float values say ranging from 0 - 18. i want to get the frequencies of the values in class intervals of 0 - 1.99, 2 - 3.99, 4 - 5.99 etc. My attempts do not give me the proper results. especially for the first class interval 0 - 1.99. HELP !!!
My program -
#include<stdio.h>
-
#define maxrl 10
-
#define bins 10
-
-
main()
-
{
-
FILE *fp1,*fp2;
-
float value[maxrl];
-
int i;
-
int group[bins];
-
-
for(i=0;i<bins;i++)
-
group[bins] = 0;
-
fp1 = fopen("RL.dat","r");
-
fp2 = fopen("RL_freq.dat","w");
-
for(i=0;i<maxrl;i++){
-
fscanf(fp1,"%f",&value[i]);
-
++group[(int)(value[i]/2)];
-
-
}
-
fprintf(fp2,"\n");
-
fprintf(fp2,"no. of bins\tbins\t frequency\n");
-
-
for(i=0;i<bins;i++) {
-
-
fprintf(fp2,"%d\t\t %2d\t\t%d \n",i+1,2*i,group[i]);
-
}
-
fclose(fp1);
-
fclose(fp2);
-
}
2 2447 sicarie 4,677
Recognized Expert Moderator Specialist
Please use code tags around your code, they help greatly with readability.
Ok, you have a few issues here - you have a for loop with no { } statement, an undefined variable (bins), and it doesn't look like you have started the part where you count the ranges. If this is for a class assignment, I would recommend sitting down with your teacher for a few hours - there's some fundamental stuff here that needs to be fixed, and you need help with the algorithm/logic of the program.
dear all
i want and as fast as possible a working C program for the following problem.
i have an array values[ ] consisting of 'n' float values say ranging from 0 - 18. i want to get the frequencies of the values in class intervals of 0 - 1.99, 2 - 3.99, 4 - 5.99 etc. My attempts do not give me the proper results. especially for the first class interval 0 - 1.99. HELP !!!
My program -
#include<stdio.h>
-
#define maxrl 10
-
#define bins 10
-
-
main()
-
{
-
FILE *fp1,*fp2;
-
float value[maxrl];
-
int i;
-
int group[bins];
-
-
for(i=0;i<bins;i++)
-
group[bins] = 0;
-
fp1 = fopen("RL.dat","r");
-
fp2 = fopen("RL_freq.dat","w");
-
for(i=0;i<maxrl;i++){
-
fscanf(fp1,"%f",&value[i]);
-
++group[(int)(value[i]/2)];
-
-
}
-
fprintf(fp2,"\n");
-
fprintf(fp2,"no. of bins\tbins\t frequency\n");
-
-
for(i=0;i<bins;i++) {
-
-
fprintf(fp2,"%d\t\t %2d\t\t%d \n",i+1,2*i,group[i]);
-
}
-
fclose(fp1);
-
fclose(fp2);
-
}
Among other things, you're not zeroing your group bins because you're not using 'i' in your 'for' loop. So your numbers will be completely wacky.
You really should also check the returns from your fopens, etc... and be very careful with floats generally.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: malv |
last post by:
Simple case:
In this list, how to find all occurences of intervals of n adjacent
indexes having at least one list-member with a value between given
limits.
Visualizing the list as a two-dimensional curve, this is like
horizontally dragging a given rectangle over the curve and finding the
x coordinates where the curve passes through the rectangle.(Define such
a x-index coordinate as the left corner of the rectangle.)
More complicated...
|
by: RadiationX |
last post by:
How does this program work?
// fig06_07.c -- COP2220 Example -- 040209 (sjd)
// Student poll program
#include <stdio.h>
#include <stdlib.h>
#define RESPONSE_SIZE 40 // number of survey responses
|
by: genestarwing |
last post by:
QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of occurences.
The second is to let you enter a word, with the program reporting how
many times the...
|
by: bsn525 |
last post by:
Consider the marks scored by students of the programming module. Allow the user to enter the number of students. The user shall then enter the marks for each student. Thus if there are 10 students, the user will enter 10 marks.
Let us take the following scenario for the 10 students:-
46 37 28 87 76 83 76 38 76 37
Your program must now calculate
(i) the frequency for each mark
(ii) the interval which exists between identical marks
In...
|
by: Neehar |
last post by:
Hello
For one of the interviews I took recently, I was given an offline
programming quiz.
In 30 minutes I had to write code in C++ to counts the number of times
each unique word appears in a given file.
I tried my level best even after the quiz to come up with a solution
but cudnt find an efficient one. :(
This is what I did.
| |
by: Andrew Savige |
last post by:
I'm learning Python by reading David Beazley's "Python Essential Reference"
book and writing a few toy programs. To get a feel for hashes and sorting,
I set myself this little problem today (not homework, BTW):
Given a string containing a space-separated list of names:
names = "freddy fred bill jock kevin andrew kevin kevin jock"
produce a frequency table of names, sorted descending by frequency.
then ascending byname. For...
|
by: Larry |
last post by:
Dear all,
I'm new to Python. I have a file (an image file actually) that I need
to read pixel by pixel. It's an 8-bit integer type. I need to get the
statistics like mean, standard deviation, etc., which I know a little
bit already from reading numpy module. What I want to know is how to
get the number of occurences of numeric element in an array. Say,
b = array(()
|
by: Sejoro |
last post by:
I fixed the operand problem (thanks) and now a new one has risen up. I have to compile it with a makefile which I have made and I am getting more strange errors I don't know how to fix.
Well, first of all, I don't know how to open a file in one function and use the same ifstream in another function in a separate file.
And second of all, I keep getting the following error:
Undefined first referenced
symbol ...
|
by: pereges |
last post by:
I have a C program which I created on Windows machine. I have compiled
and executed the program on windows machine and it gives me the
consistent output every time i run it. for eg.
input a = 2, b =3
lets say a sum operation is to be performed, then:
output: 5
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |