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 ,...

  • Consider the following, partially-complete, C-program: #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #define BUFFERSIZE 100 #define COPYMODE...

    Consider the following, partially-complete, C-program: #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #define BUFFERSIZE 100 #define COPYMODE 0644 main(int argC, char* argv[]) {    int srcFd;    int dstFd;    int charCnt;    char buf[BUFFERSIZE];    /*Check args*/    if( argC!=3 ){        fprintf( stderr, "usage: %s source destination\n", argv[0]);        exit(1);    }    /*Open the files*/       srcFd= open(argv[1],O_RDONLY);    if( srcFd==-1 ){        fprintf(stderr,"Cannot open %s \n", argv[1]);    }    dstFd= creat(argv[2],COPYMODE);   ...

  • 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...

  • This question has been asked before but the responses have been wrong. Please do not copy...

    This question has been asked before but the responses have been wrong. Please do not copy and paste their answers. Currently the program opens a file and reads every byte in the file and write both the ASCII hex value for that byte as well as it’s printable character to standard output with non-printable characters printing a "." Now, I want have an option where the program prints in binary instead of hex by typing "-b" at the command line....

  • 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...

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