0% found this document useful (0 votes)
3 views26 pages

Week 3 c Programming

The document contains a graded assignment for a programming course focused on C language concepts. It includes questions on header files, comments, variable declarations, Boolean conditions, operator precedence, and code outputs. Additionally, it provides code snippets for various calculations and programming tasks.

Uploaded by

sumitsisodiya790
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views26 pages

Week 3 c Programming

The document contains a graded assignment for a programming course focused on C language concepts. It includes questions on header files, comments, variable declarations, Boolean conditions, operator precedence, and code outputs. Additionally, it provides code snippets for various calculations and programming tasks.

Uploaded by

sumitsisodiya790
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

GRADED ASSIGNMENT

GRADED ASSIGNMENT

WEEK 3
WEEK 3

PROGRAMMING
PROGRAMMING

ELECTROWORLD
ELECTROWORLD
In C programming, what
is the purpose of a
header file?

To include function
declarations and macros.
Which of the following is a
valid comment in C?

// This is a comment
/* This is a comment */
Which of the following
are valid variable names
in C?

Number_2
Number3
Which of the following are
valid ways to declare a long
variable in C?

long a;
lont int a;
signed long a;
What is the value of a
after the execution of
the following code?

30
What will be the final
value of j?

8
Which statement
correctly assigns the
value 20 to variable a?
Consider that all given
variables are integer.

a = x = y = 20;
Which of the following
statements about Boolean
conditions in C is true?

In C, 0 represents false, and any


non-zero value represents true.
Which is the correct order of
precedence (highest to
lowest) among these
operators?

Arithmetic → Logical AND


(&&) → Assignment (=)
What will be the output of the
following program?

Compilation error
What will be the output of the
following program?

15
What will be the output
of the program?

Compilation error
What will be the output
of the program?

ABC3
What will be the output of
the given code snippet?

0
What will be the value of x, y
and z after executing the
given code snippet?

x = 2, y = 3, z = 1
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);

COPY & PASTE


//1 hours = 3600 seconds
hours = timeInSeconds/3600;
minutes = (timeInSeconds/60)-(hours*60);
seconds=timeInSeconds-(minutes*60)-(hours*3600);

COPY & PASTE


int n,b,c,sum;
n=num/1000;
b=num/100;
c=num/10;
sum=n+b-(n*10)+c-(n*100)-((b-(n*10))*10)+num%10;

COPY & PASTE


double cfrac=x+1.0/(x+1.0/(x+1.0/(x+1.0/(x+1.0/x))));

COPY & PASTE


double area,s;

s=(a+b+c)/2;

area=sqrt(s*(s-a)*(s-b)*(s-c));

COPY & PASTE


totalCost=pi*(diameter/2)*(diameter/2)*costPerSqInch+numToppings*costperTopping;

COPY & PASTE


#include <stdio.h>

int main()
{
// Initialize required Variables
double weight, rate, cost;

// Read Inputs: weight of the package (in kilograms) a


shipping rate
scanf("%lf", &weight);
scanf("%lf", &rate);

// Calculate the shipping cost


cost = weight * rate;

// Print the shipping cost as double up to two decimal point


printf("%.2lf\n", cost);

return 0;
}
COPY & PASTE
#include <stdio.h>

int main()
{
int age, gender;
double weight, height, activityFactor, calories;

// Read inputs: age, gender, weight, height and activity factor


scanf("%d", &age);
scanf("%d", &gender);
scanf("%lf", &weight);
scanf("%lf", &height);
scanf("%lf", &activityFactor);

// Calculate the recommended daily calorie intake


if (gender == 1)
{
// Male calorie intake formula
calories = (88.362 + (13.397 * weight) + (4.799 * height) - (5.677 * age)) * activityFactor;
}
if (gender == 2)
{
// Female calorie intake formula
calories = (447.593 + (9.247 * weight) + (3.098 * height) - (4.330 * age)) * activityFactor;
}

// Print the output up to two decimal points


printf("%.2lf\n", calories);

return 0;
}

COPY & PASTE


@electroworld1

You might also like