Shop NFL, MLB, NBA, NCAA, Sports Fan Apparel, Hats, Gifts, Tees, Sweatshirts, & Jerseys for men’s and women from SportsManiaUSA.com. We bring you the best sport https://sportsmaniausa.com/
1. Answer the following question about Programming in C
Q1. What is unusual about the logical operators? Explain how you can jump from one function
to another.
Answer :- Logical operators are unusual because they allow you to perform operations on
Boolean values (true or false) rather than numerical values. They are often used in conditional
statements, such as if-else statements, to control the flow of a program. You can jump from one
function to another by using the logical operator "goto" which directs the execution of a program
to a specific labeled location, however it's not recommended to use it as it makes the code less
readable and harder to maintain.
Q2. Create a structure for Date (dd, mm, yy), enter two dates in D1 and D2, write program that
print the greater date among them.
Answer :- struct Date {
int day;
int month;
int year;
};
struct Date D1, D2;
//Enter two dates in D1 and D2
scanf("%d %d %d", &D1.day, &D1.month, &D1.year);
scanf("%d %d %d", &D2.day, &D2.month, &D2.year);
//Compare two dates and print the greater date
if (D1.year > D2.year) {
printf("%d-%d-%d", D1.day, D1.month, D1.year);
} else if (D1.year == D2.year) {
if (D1.month > D2.month) {
printf("%d-%d-%d", D1.day, D1.month, D1.year);
} else if (D1.month == D2.month) {
if (D1.day > D2.day) {
printf("%d-%d-%d", D1.day, D1.month, D1.year);
} else {
printf("%d-%d-%d", D2.day, D2.month, D2.year);
}
} else {
printf("%d-%d-%d", D2.day, D2.month, D2.year);
}
} else {
printf("%d-%d-%d", D2.day, D2.month, D2.year);
}
2. Q3. Discuss the guidelines for drawing flowcharts and their advantages. Draw a flowchart to find
the sum of first 50 natural numbers.
Answer :- Guidelines for flowcharts include using standardized symbols, proper alignment and
spacing, and clear labeling. Their advantages include improved communication and
understanding of processes, identification of bottlenecks and inefficiencies, and ease of making
changes. Draw a flowchart for finding the sum of first 50 natural numbers:
Q4. What are functions? Create a function to find the factors of the number.
Answer :- Functions are blocks of code that perform a specific task and can be reused
throughout a program. They allow for better organization and modularity. Here's an example
function in C to find the factors of a number:
void factors(int num) {
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
printf("%d ", i);
}
}
}
Q5. What is the difference between high and low level filing? Write a program to display
contents of a file on the screen.
Answer :- High-level filing refers to the organization of data based on the meaning of the data,
such as by category, subject, or customer, while low-level filing refers to the organization of data
based on the physical characteristics of the data, such as by size, color, or shape. Here's an
example program that displays contents of a file on the page.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream file;
file.open("example.txt");
string line;
3. while (getline(file, line))
{
cout << line << endl;
}
file.close();
return 0;
}
Q6. Discuss the concepts of Duration, Scope and Linkage to control accessibility throughout a
program.
Answer ;-Duration, scope, and linkage are the three concepts that control accessibility
throughout a program.
1. Duration refers to the lifetime of a variable or an object in the memory. It tells you how
long a variable or an object will exist in the memory.
2. Scope refers to the region of the program where a variable or an object can be
accessed. It tells you where a variable or an object can be accessed in the program.
3. Linkage refers to the association of a variable or an object with a program or module. It
tells you whether a variable or an object can be accessed by other programs or
modules.
Q7. Write a program to check whether the entered number is odd or even.
Answer :- #include <stdio.h>
int main(){
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("%d is even", num);
else
printf("%d is odd", num);
return 0;
}
Q8. Write short notes on Pointers and Expressions involving pointers.
Answer :- Pointers are variables that hold the memory addresses of other variables. They allow
you to manipulate memory directly and can improve the performance of a program. Expressions
involving pointers include:
1. Dereferencing a pointer: accessing the value stored at the memory address held by the
pointer.
2. Assigning a pointer: assigning the memory address of a variable to a pointer.
3. Arithmetic operations on pointers: adding or subtracting an integer from a pointer, which
moves the pointer to a different memory location.