
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define FILE_IN "lab4.dat"
//define FILE_IN "lab4sample.dat"
#define FILE_OUT "lab4.out"
int main(void)
{
double radius, height, area, volume;
int count;
FILE * In;
FILE * Out;
In = fopen(FILE_IN, "r");
if (In == NULL) {
printf("Error on opening the input file \n");
}
Out = fopen(FILE_OUT, "w");
if (Out == NULL) {
printf("Error on opening the output file \n");
}
fprintf(Out, "Name. Lab4. \n");
while((fscanf(In, "%lf%lf", &radius, &height)) == 2) {
area = M_PI * radius * radius;
volume = M_PI * radius * radius * height;
count++;
fprintf(Out, "\nCylinder %1d", count);
fprintf(Out, "\nThe radius is: %9.3f", radius);
fprintf(Out, "\nThe height is: %9.3f", height);
fprintf(Out, "\nThe top area is: %9.3f", area);
fprintf(Out, "\nThe volume is: %9.3f\n", volume);
}
fclose(In);
fclose(Out);
return EXIT_SUCCESS;
}
for C
Here is code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define FILE_IN "lab4.dat"
//define FILE_IN "lab4sample.dat"
#define FILE_OUT "lab4.out"
int main(void)
{
double radius, height, area, volume;
int count = 0;
FILE *In;
FILE *Out;
In = fopen(FILE_IN, "r");
if (In == NULL)
{
printf("Error on opening the input file \n");
}
Out = fopen(FILE_OUT, "w");
if (Out == NULL)
{
printf("Error on opening the output file \n");
}
fprintf(Out, "Name. Lab4. \n");
while ((fscanf(In, "%lf%lf", &radius, &height)) == 2)
{
area = M_PI * radius * radius;
volume = M_PI * radius * radius * height;
count++;
fprintf(Out, "\nCylinder %d", count);
fprintf(Out, "\nThe radius is: %9.3f", radius);
fprintf(Out, "\nThe height is: %9.3f", height);
fprintf(Out, "\nThe top area is: %9.3f", area);
fprintf(Out, "\nThe volume is: %9.3f\n", volume);
}
fclose(In);
fclose(Out);
return EXIT_SUCCESS;
}
Output:

#include <stdio.h> #include <stdlib.h> #include <math.h> #define FILE_IN "lab4.dat" //define FILE_IN "lab4sample.dat" #define FILE_OUT "lab4.out" int...
Convert this code from C to C++
include <stdio.h> include <locale.h> void filtre (double x. double yll, double yol, int , int N) int Nn-10000 int main) setlocale (LC ALL,") double x(Nm) , y [ Nm],yo Nml®(0.0); int m; FILE dosyal-fopen("D:/veri/673.txtr FILE dosya2-fopen("D:/veri/data2.txt int i-0 while( feof (dosyal)) fscanf (dosyal, " ",xi sytil) fclose (dosyal) int Nij printf("Pencere Genişligi scanf() 3 filtre(x,y.Yo,m,N) for(int k-0keNkt+)fprintf (dosya2, 10.41 10.411 0.41fn",x[k],y[k].yo[k]) fclose(dosya2) void filtre (double x double y. double yoll, int m, int...
Heres what I have so far:
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define pi 3.14159
#define inputfile "c:\\engr 200\\oil_explore.txt"
#define outputfile "c:\\engr 200\\oil_report.txt"
/* Main function */
int main(void)
{
/* Declare variables */
double ratio, depth, ideal_charge, length, weight, number_sticks,
wellsite;
int i;
FILE *explore, *report;
/* Open input file */
explore = fopen(inputfile,"r");
report = fopen(outputfile,"w");
/* Verify input file */
if(explore == NULL)
{
printf("\n\nERROR OPENING INPUT FILE\n\nPROGRAM
TERMINATED\n\n");
return 0;
}
/* Read...
Can someone explain what the purpose of the program below is? #include<stdio.h> #include<string.h> main() { FILE*fp; int i; char s[40]; fp=fopen("text.txt","r"); for(i=0;i<100;i++) fprintf(fp,"%c",'a'); fprintf(fp, "\n"); for(i=0;i<100;i++) fprintf(fp, "%c", 'b'); fprintf(fp, "\n"); for(i=0;i<100;i++) fprintf(fp, "%c", 'c'); fprintf(fp, "\n"); fgets(s,10,fp); printf("%s\n",s); fgets(s,40,fp); printf("%s\n",s); fgets(s,40,fp); printf("%s\n",s); fgets(s,40,fp); printf("%s\n",s); fclose(fp); }
#include <stdio.h> #include <stdlib.h> #include <math.h> int count,i, tracker = 0; int main() { scanf("%d\n", &count); int numbers[count]; //GEtting the numbers and satisfy BS conditions for (i = 0; i < count; i++) { if (scanf("%d", &numbers[i]) != EOF) { tracker++; } if (numbers[i] < 0 || numbers[i] > 99) { printf("%d is not in the [0, 99] range.\n",numbers[i]); exit(i); } } if( tracker != count) { printf("%d numbers are required, but only %d were provided.\n", count, tracker); exit(1); }...
#include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <pthread.h> pthread_mutex_t mtx; // used by each of the three threads to prevent other threads from accessing global_sum during their additions int global_sum = 0; typedef struct{ char* word; char* filename; }MyStruct; void *count(void*str) { MyStruct *struc; struc = (MyStruct*)str; const char *myfile = struc->filename; FILE *f; int count=0, j; char buf[50], read[100]; // myfile[strlen(myfile)-1]='\0'; if(!(f=fopen(myfile,"rt"))){ printf("Wrong file name"); } else printf("File opened successfully\n"); for(j=0; fgets(read, 10, f)!=NULL; j++){ if (strcmp(read[j],struc->word)==0)...
Create another program that will prompt a user for input file. The user will choose from 4 choices: 1. Display all positive balance accounts. 2. Display all negative balance accounts. 3. Display all zero balance accounts. 4. End program. C PROGRAMMING my code so far #include<stdlib.h> #include<stdio.h> int main(void) { int request; int account; FILE *rptr; char name[20]; double balance; FILE *wptr; int accountNumber; if((wptr = fopen("clients.dat","w")) == NULL) { puts("File could not be opened"); } else {...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...
convert this code from C to C++
include <stdio.h> include <locale.h> void filtre (double x. double yll, double yol, int , int N) int Nn-10000 int main) setlocale (LC ALL,") double x(Nm) , y [ Nm],yo Nml®(0.0); int m; FILE dosyal-fopen("D:/veri/673.txtr FILE dosya2-fopen("D:/veri/data2.txt int i-0 while( feof (dosyal)) fscanf (dosyal, " ",xi sytil) fclose (dosyal) int Nij printf("Pencere Genişligi scanf() 3 filtre(x,y.Yo,m,N) for(int k-0keNkt+)fprintf (dosya2, 10.41 10.411 0.41fn",x[k],y[k].yo[k]) fclose(dosya2) void filtre (double x double y. double yoll, int m, int...
#include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc < 4) { fprintf(stderr, "usage: %s <input file 1> <input file 2> <output file>\n", argv[0]); exit(EXIT_FAILURE); } } /* This function takes in the two input file names (stored in argv) and determines the number of integers in each file. If the two files both have N integers, return N, otherwise return -1. If one or both of the files do not exist, it...
#include <errno.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> /* * Expected usage: * ./wc <words | lines> <file> * * If argv[1] is "words", then you should count the number of words. If it * is "lines", then you should count the number of lines. * * For example: * $ cat a.txt * a b c d * $ ./wc words a.txt * 4 * $ ./wc lines a.txt * 1 * * YOUR PROGRAM...