Question

In: Computer Science

C programing language A file "data.txt" contains only integers. Write a code to find average of...

C programing language

  1. A file "data.txt" contains only integers. Write a code to find average of all values and print the average
  2. How would you use execlp function to execute "ps –e –a –l" command
  3. char *dt = "The five boxing wizards jump quickly";
  1. write a program to count frequency of each letter, ignore case. Print the letter and frequency of each letter.

// 1A: . Ask the user to enter a password string, store it in pass. Password should contain atleast one Upper case, one Lower case letter , one of the 0-9 digits

Solutions

Expert Solution

(1)

#include<stdio.h>
int main(){
   FILE*fptr;
   fptr = fopen("data.txt","r");
   double sum=0;
   int count=0,value;
  
   while(fscanf(fptr, "%d", &value) != EOF){
       count++;
       sum+=value;
   }
  
   printf("Average value : %d\n",sum/value);
   fclose(fptr);
   return 0;
}

(2)

#include<stdlib.h>

int main(){
   char *dt = "The five boxing wizards jump quickly";
   int count[26],i;
   for(i=0;i<26;i++)count[i] = 0;
  
   i=0;
   while(dt[i] != '\0'){
       char ch = dt[i++];
       if(ch >= 'A' && ch <='Z')count[ch-'A']++;
       if(ch >= 'a' && ch <='z')count[ch-'a']++;
   }
  
   for(i=0;i<26;i++){
       if (count[i]!=0)printf("%c-%d\n",(i+'a'),count[i]);
   }
   return 0;
}

(3)

#include<stdio.h>
#include<string.h>

int main(){
   char password[25];
   int upper,lower,digit,i;
  
  
   while(1){
       upper=0;lower=0;digit=0;
       printf("Enter password : ");
       scanf("%s",password);
  
       for(i=0;i<strlen(password);i++){
           char ch = password[i];
           if(ch>='A' && ch<='Z')upper++;
           if(ch>='a' && ch<='z')lower++;
           if(ch>='0' && ch<='9')digit++;
       }
      
       if(upper>0 && lower>0 && digit>0)break;
       else{
           printf("Invalid password. Re-enter Password\n");
       }
   }
  
   printf("\nPassword : %s",password);
   return 0;
}


Related Solutions

Write a code to find the following in a text file (Letter). language: Python (a) Find...
Write a code to find the following in a text file (Letter). language: Python (a) Find the 20 most common words (b) How many unique words are used? (c) How many words are used at least 5 times? (d) Write the 200 most common words, and their counts, to a file. text file: Look in thy glass and tell the face thou viewest, Now is the time that face should form another, Whose fresh repair if now thou not renewest,...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
C++ programing Write a main function that  reads a list of integers from a user, adds to...
C++ programing Write a main function that  reads a list of integers from a user, adds to an array using dynamic memory allocation, and then displays the array. The program also displays the the largest element in the integer array. Requirement: Using pointer notation.
(C++) Write a program to read from a grade database (data.txt). The database (text file) has...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has students names, and grades for 10 quizzes.Use the given function prototypes to write the functions. Have main call your functions. The arrays should be declared in main() and passed to the functions as parameters. This is an exercise in parallel arrays, int and char 2 dim arrays. Function prototypes: int readData(ifstream &iFile, int scores[][10], char names[][30]); This functions takes the file stream parameter inFile...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the range of 0 to 100. There may be repeats. The numbers must not be ordered/sorted. The task is to find and print the two smallest numbers. You must accomplish this task without sorting the file and without using arrays for any purpose. It is possible that the smallest numbers are repeated – you should print the number of occurrences of the two smallest numbers....
C++ sort a file with 140 integers where only 20 integers maybe placed into memory at...
C++ sort a file with 140 integers where only 20 integers maybe placed into memory at any one time Main idea: break data into blocks, sort blocks into runs, merge runs less. Call inFile1 our source file (the one with the initial 140 records to be sorted. You will also need an inFile2, and 2 other files outFile1 and outFile2. Break the file into blocks of size 20: in this case there will be 7 blocks ( 140/20 ) Sort...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
Write a static method called max that creates a Scanner and connects to a file “data.txt”....
Write a static method called max that creates a Scanner and connects to a file “data.txt”. Use an exception handling  mechanism of your choice. The method should read the file until the end of time and consume tokens that could be integer,  double or string type. It should count and return the number of words that are not integer or doubles.
CORAL LANGUAGE ONLY Write a program whose inputs are three integers, and whose outputs are the...
CORAL LANGUAGE ONLY Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. If the input is 7 15 3, the output is: largest: 15 smallest: 3 Your program should define and call two functions: Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum The function LargestNumber should return the largest number of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT