Question
this is in C programming language
1. Write a printf or scanf statement for each of the following: a) Print unsigned integer 1001 right justified in a 10-digit
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h> #include<stdlib.h>#include<malloc.h>#include<string.h>void main() { unsigned int a = 1001; printf(Partelse { m = realloc(m, i+1 * sizeof(char)); //increase size of array by reallocation as more characters are read, m[i] = ch; iprintf(hour: %d minute: %d second: %d\n, hour, min, sec);

#include<stdio.h>

#include<stdlib.h>

#include<malloc.h>

#include<string.h>

void main(){

    unsigned int a = 1001;

    printf("Part A: \n"); //10 is used to denote number of fields and u is used for unsigned integers

    printf("Right Justified Output:%10u\n",a);

    int b;

    printf("Part B: \n");

    printf("Enter hexadecimal value: ");

    scanf("%x", &b);//Hexadecimal values represented by x

    printf("Hexadecimal value is: %x, in decimal: %d\n",b,b); //Printed decimal values as well for clarity

    printf("Part C: \n");

    int c = 300;

    // I have used signed and unsigned notifications here, please clarify in case you need something else

    printf("Signed: %d, Unsigned: %u\n",c,c);

    printf("Part D: \n");

    int d = 200;

    printf("Hexadecimal: 0x%x\n",d); //printed hexadecimal and added '0x' as mentioned

    printf("Part E: \n");

    char *m = (char*)malloc(1*sizeof(char)); //initialised dynamic array

    char ch = 'a'; int i=0;

    while(ch!='z'){

        printf("Enter character: ");

        scanf("%*c%c", &ch); // read characters until z encountered, a %*c at start because scanf adds extra new line which we ignore

        if(i==0){

            m[i] = ch;

            i++;

        }

        else{

            m = realloc(m, i+1 * sizeof(char)); //increase size of array by reallocation as more characters are read

            m[i] = ch;

            i++;

        }

    }

    for(int j=0; j<i; j++)

        printf("%c",m[j]);

    free(m); // free memory

    printf("\n");

    printf("Part F: \n");

    float e = 7.350;

    printf("%07.3f\n",e); // 07 denoted total number of fields out of while 3 are to remain after decimal point

    printf("Part G: \n");

    int hour,min,sec;

    printf("Enter value of date: ");

    scanf("%d%*c%d%*c%d", &hour, &min, &sec); // when we use *c, it ignores the character input at that position in this cas '-'

    printf("hour: %d minute: %d second: %d\n",hour,min,sec);

    printf("Part H:\n");

    char str[50];

    scanf("%s",str);

    char *ptr = str;

    ptr++;

    ptr[strlen(ptr)-1] = '\0'; //Used character pointer to remove first and last element

    for(;*ptr!='\0';ptr++)

        printf("%c",*ptr);

    printf("\n");

    printf("Part I: \n");

    printf("Enter value of time: ");

    scanf("%d:%d:%d", &hour, &min, &sec); //Used ':' notation in between scanf so compiler automatically ignores thos

    printf("hour: %d minute: %d second: %d\n", hour, min, sec);

}

The desired output:

Part A: Right Justified Output: 1001 Part B: Enter hexadecimal value: ffd Hexadecimal value is: ffd, in decimal: 4093 Part C:


answered by: ANURANJAN SARSAM
Add a comment
Answer #2

#include<stdio.h> #include<stdlib.h> #include<malloc.h> #include<string.h> void main() { unsigned int a = 1001; printf(Partelse { m = realloc(m, i+1 * sizeof(char)); //increase size of array by reallocation as more characters are read, m[i] = ch; iprintf(hour: %d minute: %d second: %d\n, hour, min, sec);

#include<stdio.h>

#include<stdlib.h>

#include<malloc.h>

#include<string.h>

void main(){

    unsigned int a = 1001;

    printf("Part A: \n"); //10 is used to denote number of fields and u is used for unsigned integers

    printf("Right Justified Output:%10u\n",a);

    int b;

    printf("Part B: \n");

    printf("Enter hexadecimal value: ");

    scanf("%x", &b);//Hexadecimal values represented by x

    printf("Hexadecimal value is: %x, in decimal: %d\n",b,b); //Printed decimal values as well for clarity

    printf("Part C: \n");

    int c = 300;

    // I have used signed and unsigned notifications here, please clarify in case you need something else

    printf("Signed: %d, Unsigned: %u\n",c,c);

    printf("Part D: \n");

    int d = 200;

    printf("Hexadecimal: 0x%x\n",d); //printed hexadecimal and added '0x' as mentioned

    printf("Part E: \n");

    char *m = (char*)malloc(1*sizeof(char)); //initialised dynamic array

    char ch = 'a'; int i=0;

    while(ch!='z'){

        printf("Enter character: ");

        scanf("%*c%c", &ch); // read characters until z encountered, a %*c at start because scanf adds extra new line which we ignore

        if(i==0){

            m[i] = ch;

            i++;

        }

        else{

            m = realloc(m, i+1 * sizeof(char)); //increase size of array by reallocation as more characters are read

            m[i] = ch;

            i++;

        }

    }

    for(int j=0; j<i; j++)

        printf("%c",m[j]);

    free(m); // free memory

    printf("\n");

    printf("Part F: \n");

    float e = 7.350;

    printf("%07.3f\n",e); // 07 denoted total number of fields out of while 3 are to remain after decimal point

    printf("Part G: \n");

    int hour,min,sec;

    printf("Enter value of date: ");

    scanf("%d%*c%d%*c%d", &hour, &min, &sec); // when we use *c, it ignores the character input at that position in this cas '-'

    printf("hour: %d minute: %d second: %d\n",hour,min,sec);

    printf("Part H:\n");

    char str[50];

    scanf("%s",str);

    char *ptr = str;

    ptr++;

    ptr[strlen(ptr)-1] = '\0'; //Used character pointer to remove first and last element

    for(;*ptr!='\0';ptr++)

        printf("%c",*ptr);

    printf("\n");

    printf("Part I: \n");

    printf("Enter value of time: ");

    scanf("%d:%d:%d", &hour, &min, &sec); //Used ':' notation in between scanf so compiler automatically ignores thos

    printf("hour: %d minute: %d second: %d\n", hour, min, sec);

}

The desired output:

Part A: Right Justified Output: 1001 Part B: Enter hexadecimal value: ffd Hexadecimal value is: ffd, in decimal: 4093 Part C:Since questions were all part of single question, I just wrote a single program for all the questions, please comment if you need separately. Also please comment if you have any doubts and do give a thumbs up if you liked the answer

Add a comment
Know the answer?
Add Answer to:
this is in C programming language 1. Write a printf or scanf statement for each of...
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
  • C PROGRAMMING      Write a printf or scanf statement for each of the following: a) Print...

    C PROGRAMMING      Write a printf or scanf statement for each of the following: a) Print unsigned integer 2001 right justified in a 12-digit field with 6 digits. b) Print 3.150 in a 9-digit field with preceding zeros. // part of my answer: Printf(“%09 c) Read a time of the form hh-mm-ss, storing the parts of the time in the integer variables hour, minute and second. Skip the dash (-) in the input stream. Use the assignment suppression character. d)...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

  • C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention...

    C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention to the rules at the bottom. Extra good rating to whoever can help me with this. TIA. In certain programming situations, such as getting information from web forms, via text boxes, the data coming in may need to be numerical (we want to perform arithmetic on it), but it is stored in the form of a list of characters (the numerical value stored is...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

  • (c programming): write a program that contains a function named getName, that does not get any...

    (c programming): write a program that contains a function named getName, that does not get any parameter and returns a character array of a random name from a constant list of 30 names, in a global array. the function returns that random name. each name in the list is a character string that consists of not more than 20 characters(not including finishing 0). the name consists of only characters from the american alphabet (a-zA-Z) and does not contain any "white"...

  • write codes and give detailed explanation of how to execute. What you need to turn in:...

    write codes and give detailed explanation of how to execute. What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word or PDF...

  • Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...

    Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • Please help me with the following C Programming project. I am providing the code I used...

    Please help me with the following C Programming project. I am providing the code I used which needs to be reworked to add the following requirements. Here is my code #include<stdio.h> char input; int main() { int i = 0; while (true){ scanf_s("%c", &input); if (input == 'X') break; printf("%c", input); } return 0; } Here are the requirements for the code plus and additional note what the code should have. Goals Understand the ASCII representation of character values. Understand...

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