Chapter 1 practice set source code

             Source code

Do you remember that I have give you a practice set so now I will give you the answers of the questions and the prompts that will help for your future in the C programming. First I want to answer the conceptual based questions that I give you to see your concepts and foundation in basics.
 Question no. 1: What are variables?     
Variables are like the container and the box that are used to store the values.
Question no. 2: What is the format specifier for integer?  
The format specifier that is used to represent integers is %d.
Question no. 3: Which format specifier is this: %f.    
This format specifier is for float.
Question no. 4: What are comments? Give atleast one  use of them.
Comments are the stemtement that are created for user that are ignored by the compiler. The use of comments is that it is useful for the person who is learning the C language or to mention the title when the user see this again so he understand that it is made for this use. The another use of comments is that it is useful for the fellow programmer to understand the code because when he see the program so he understand some new things that he do not know.
Question no. 5: What are the types of comments?
1: Single line comment.
2: Multi line comment. 
 Question no. 6: What is the syntax for the taking input from the user?
To get the input from the user we use scanf() function so the syntax for this is as follows
Syntax for scanf()
scanf("format_specifier_for_the_data_type", Variable_name); // semicolon is must
first_variable + second_variable

Now the turn is for AI skills questions. I will only give you the prompts because this skill is very important to make your learning and you productive so it is my responsibility to tell you about these important skills. Search these prompts from ChatGPT.
1: "Hey tell me the names of keywords in C and tell me how many keywords are in C language"
2; "Tell me the names of simple airthmetic opreations in C language and tell me thier opreators also"
3: "Tell me the basic structure of a C program".
4"Tell me the names of format specifier used for print Long, Double, and String".

Now it is time for the guess the output  and fixing the error question
                                   Program1: problem1 corrected code.c
 
#include <stdio.h>

int main(){
    int a;
    scnaf("%d", &a);
    printf("%d", a);
    return 0;
}

This program is for to get input from the user

                                  Program2:  problem2 corrected code.c
#include <stdio.h>

int main(){
    int a = 3;
    int b = 4;
    return 0;
}

This is for to declare the variables Now what were the errors and outputs of these problems here are they


problem1.c output
343928349394 (Garbage value) it means when the value is not initialized so it stores any value called Garbage
value

Problem1 correct.c

7
7

problem2.c output
Error, missing ';'

problem2 correct code.c  output





Now this is the time for the programmes that I give you as homework. Now there are the answer
Question no.1 Write a program to calculate the surface area of squar
Part a: Using hard coded inputs
#include <stdio.h>

int main(){
    int l = 5;
    printf("The surface area of the squar is %d", l*l);
    return 0;
}
Part b: Taking input from the user
#include <stdio.h>

int main(){
    int l;
    printf("Enter the length of the squar:  ");
    scanf("%d", &l);
    printf("The surface area of the squar is %d", l*l);
    return 0;
}

Question no. 2: Write a program to calculate the area of a circle?
Part a: Using hard coded inputs
#include <stdio.h>

int main(){
    float radius = 21.23;
    float pi = 3.14;
    printf("The area of the circle is %.2f\n", pi * radius * radius);
    return 0;
}
Part b: Input getting from the user
#include <stdio.h>

int main(){
    float radius;
    printf("Enter the radius of the circle:  ");
    scanf("%f", &radius);
    float pi = 3.14;
    printf("The area of the circle is %.2f",  pi*radius*radius);
    return 0;
}
Question no. 3: Write a program to calculate the perimeter of rectangle?
Part a: Using hard coded inputs.
#include <stdio.h>

int main(){
    int Length = 6;
    int breadth = 4;
    int perimeter = 2 * (Length + breadth);
    printf("The perimeter of the rectangle is %d", perimeter);
    return 0;
}
Part b: Taking input from the user.
#include <stdio.h>

int main(){
    int Length;
    int breadth;
    printf("Enter the length and breadth of rectangle:  ");
    scanf("%d %d", &Length, &breadth);
    printf("The perimeter of the rectangle is %d", 2 * (Length + breadth));
    return 0;
}
Question no. 4: Write a program to convert the tempreature from Kelvin to Fehernhiet?
Part a: Using hard coded inputs
#include <stdio.h>

int main(){
    float K = 300.00;
    printf("The tempreature in Fehrenhiet is %.2f", (K - 273.15)*9.00/5.00+32.00);
    return 0;
}
Part b: Taking input from the user
#include <stdio.h>

int main(){
    float K;
    printf("Enter the tempeature of your home in Kelvin:  ");
    scanf("%f", &K);
    printf("The tempreature in Fehrenhiet is %.2f", (K - 273.15)*9.00/5.00+32.00);
    return 0;
}
Question no.5 : Write a program to do division?
part a: By hard coded inputs
#include <stdio.h>

int main(){
    float a = 4.00;
    float b = 16.00;
    printf("The answer is %.2f", a/b);
    return 0;
}
Part b: By taking input from the user
#include <stdio.h>

int main(){
    float a;
    float b;
    printf("Enter two numbers:  ");
    scanf("%d %d", &a, &b);
    printf("The answer is %.2f", a/b);
    return 0;
}
Quetion no. 6 Write a program to calculate the average of the students?
Part a: By hard coded inputs
#include <stdio.h>

int main(){
    float sub1 = 44.00;
    float sub2 = 45.00;
    float sub3 = 50.00;
    printf("The average is %.2f", sub1+sub2+sub3 / 3);

    return 0;
}
Part b: By taking input from the user
#include <stdio.h>

int main(){
    float sub1;
    float sub2;
    float sub3;
    printf("Enter the marks of subject 1, subject2, subject3:  ");
    scanf("%f %f %f", &sub1, &sub2, &sub3);
    printf("The average is %.2f", sub1+sub2+sub3 / 3);

    return 0;
}
 Question no. 7 Write a program to convert celsius into Fehrenhiet?
Part a: By hard coded inputs
#include <stdio.h>

int main(){
    float clesius = 100.00;
    printf("The tempreature in Fehrenhiet is %.2f", (clesius * 9.00 / 5.00) + 32.00);
    return 0;
}
Part b: By taking input from the user
#include <stdio.h>

int main(){
    float clesius;
    printf("Enter the tempreature of your home in celsius:  ");
    scanf("%f", &clesius);
    printf("The tempreature in Fehrenhiet is %.2f", (clesius * 9.00 / 5.00) + 32.00);
    return 0;
}
Question no. 8: Write  a program to convert 12 hours time into 24 hours time?
Part a: By hard coded inputs
#include <stdio.h>

int main(){
    float time = 4.00;
    printf("The time in 24 hours is %.2f\n", time + 12.00);
    return 0;
}
part b: By taking input from the user
#include <stdio.h>

int main(){
    float time;
    printf("Enter the time of your clock in 12 hours clock:  ");
    scanf("%f", &time);
    printf("The time in 24 hours is %.2f\n", time + 12.00);
    return 0;
}
Question no. 9: Write a program to find the volume of the cylinder?
Part a: By hard coded inputs
#include <stdio.h>

int main(){
    float r = 12.00;
    float h = 10.00;
    printf("The volume of the cylinder is %.2f", 22.00 / 7.00 * r*r * h);
    return 0;
}
Part b: By taking the input from the user
#include <stdio.h>

int main(){
    float r;
    float h;
    printf("Enter the radius and hieght of your cylinder:  ");
    scanf("%f %f", &r, &h);
    printf("The volume of the cylinder is %.2f", 22.00 / 7.00 * r*r * h);
    return 0;
}
Question no. 10: Write the program to convert the tempreature of Fehrenhiet to Rankine?
Part a: By hard coded inputs
#include <stdio.h>

int main(){
    float F = 0.00;
    printf("The tempreature in Rankine is %.2f", F + 459.67);
    return 0;
}
Part b: By taking input from the user
#include <stdio.h>

int main(){
    float F;
    printf("Enter the tempreature of your home in Fehrenhiet:  ");
    scanf("%f", &F);
    printf("The tempreature in Rankine is %.2f", F + 459.67);
    return 0;
}

If you donot understand that what is going so u have to check my chapter 1 and if you want the help so you can go to my chapter 1 source code then you have to solve this in my practice set u can also use ChatGPT for the help now see you in chapter 2 Sorry for the late chapter 1 practice set source code because I was waiting that you must have solve the chapter 1 practice set

Comments

Popular posts from this blog

Chapter 1 practice set

Chapter 1 source code

C language chapter 1