Question
Has to be in Unix!

Lab 7 Programs 1. Create a prints.c file, and copy the following into it: #include <stdio.h> int main(int argc, char * argv[]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution 1):-

C Code :-

#include <stdio.h>

int main(void) {
   double x = 1.0, y = 5.1e7;
   float pi = 3.14159f;
   int i = 0, j = 5115;
   short int m = 6;
   unsigned long int n = 51151151;
   printf ("x = %6lf\n", x);
   printf("y = %8.4lf\n", y);
   printf("pi = %.2f\n", pi);
   printf("i = %6d\n", i);
   printf("j = %.6d\n", j);
   printf("m = %d\n", m);
   printf("n = %lu\n", n);
   return 0;
}

/************ Output of the program *************
* x = 1.000000
y = 51000000.0000
pi = 3.14
i = 0
j = 005115
m = 6
n = 51151151
******************************************************/

Solution 2):-

C Code:-

#include<stdio.h>

struct date
{
int day;
int month;
int year;
};

int main()
{
struct date d1,d2;

printf("Enter first date(YYYY-MM-DD):");
scanf("%d-%d-%d",&d1.year,&d1.month,&d1.day);
printf("nEnter second date(YYYY-MM-DD):");
scanf("%d-%d-%d",&d2.year,&d2.month,&d2.day);

if ((d1.year > d2.year) || ((d1.year==d2.year) && (d1.month > d2.month)) || ((d1.year==d2.year) && (d1.month == d2.month) && (d1.day>d2.day)))
{
printf("%04d-%02d-%02d", d2.year, d2.month, d2.day);
}
else
{
   printf("%04d-%02d-%02d", d1.year, d1.month, d1.day);
}

return 0;
  
}

/***************************** Output of Program ***********************

Enter first date(YYYY-MM-DD): 1998-04-10
Enter second date(YYYY-MM-DD):1998-04-04
1996-04-04
Enter first date(YYYY-MM-DD): 1996-06-10
Enter second date(YYYY-MM-DD): 1996-04-01
1996-04-01

Enter first date(YYYY-MM-DD): 1996-04-01

Enter second date(YYYY-MM-DD): 1996-04-01

1996-04-01

***************************************************************************/

I have solve the first two question with all the subparts, please post next two question AS SEPERATE QUESTION

Add a comment
Know the answer?
Add Answer to:
Has to be in Unix! Lab 7 Programs 1. Create a prints.c file, and copy the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in C that takes a file name as the only argument on the...

    Write a program in C that takes a file name as the only argument on the command line, and prints out the number of 0-bits and 1-bits in the file int main ( int argc , char * argv [] ) { // Check if the user gave an argument , otherwise print " ERROR : no argument " // Check if the file can be read , otherwise print " ERROR : can ’t read " // Otherwise ,...

  • My question is listed the below please any help this assignment ; There is a skeleton...

    My question is listed the below please any help this assignment ; There is a skeleton code:  copy_file_01.c #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { char ch ; FILE *source , *target;    if(argc != 3){ printf ("Usage: copy file1 file2"); exit(EXIT_FAILURE); } source = fopen(argv[1], "r"); if (source == NULL) { printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } target = fopen(argv[2], "w"); if (target == NULL) { fclose(source); printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } while ((ch...

  • I have the following code....from the previous lab....the above needs to be added to what is...

    I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing)    pid_t pid;    int j;    //printf("Welcome to Project Three\n”);    // For loop*/    for (j = 1; j...

  • Suppose we have three programs aaa, bbb, ccc which are already developed, compiled and ready to...

    Suppose we have three programs aaa, bbb, ccc which are already developed, compiled and ready to execute. The first two, namely aaa and bbb, simply do some random amount of computation and write a character (respectively, 'A' and 'B to STDOUT_FILENO in a loop that is repeated 1000 times. If we run both programs at the same time, we might see different numbers of As and Bs such as AABBBAAABBBBABB. . . on the screen. The third program, namely ccc,...

  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

  • I have included what I need to do for part b, and what I have so...

    I have included what I need to do for part b, and what I have so far. I 2.2 Part B Write a default version of program to report the behavior of the Linux kernel by inspecting kernel state. The program should print the following values to the user screen or console: CPU type and model Kernel version Amount of time since the system was last booted, in thefomdmm:5s (for example, 3 days 13 hours 46 minutes 32 seconds would...

  • create case 4 do Method 1:copy item by item and skip the item you want to...

    create case 4 do Method 1:copy item by item and skip the item you want to delete after you are done, delete the old file and rename the new one to the old name. #include int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1:...

  • 1. Suppose you wrote a program that reads data from cin. You are now required to...

    1. Suppose you wrote a program that reads data from cin. You are now required to reimplement it so that you can read data from a file. You are considering the following changes. I. Declare an ifstream variable in_file II. Replace all occurrences of cin with in_file III. Replace all occurrences of > > and get_line with the appropriate operations for ifstream objects What changes do you need to make? I, II, and III II and III I and III...

  • Write a complete C program that inputs a paragraph of text and prints out each unique...

    Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...

  • How would I change the following C code to implement the following functions: CODE: #include <stdio.h>...

    How would I change the following C code to implement the following functions: CODE: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { if (argc != 2) printf("Invalid input!\n"); else { FILE * f = fopen (argv[1], "r"); if (f != NULL) { printf("File opened successfully.\n"); char line[256]; while (fgets(line, sizeof(line), f)) { printf("%s", line); } fclose(f); } else { printf("File cannot be opened!"); } } return 0; } QUESTION: Add a function that uses fscanf like this:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT