0% found this document useful (0 votes)
5 views

Assignment no 2

Uploaded by

mohsinsherazi63
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Assignment no 2

Uploaded by

mohsinsherazi63
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Q1: Explain format specifier of c programming and use them

make a list and describe built in function in c.


Format specifiers in C programming are used to specify the type of data to be
input or output during formatted input/output operations. They define how the
data should be interpreted or displayed.

Here's a list of commonly used format specifiers in C along with their


descriptions:
%d:
Used for printing or scanning integers (signed decimal).
%f:
Used for printing or scanning floating-point numbers.
%c:
Used for printing or scanning characters.
These format specifiers are used with functions like printf(), scanf(), sprintf(),
sscanf(), and others to format input and output according to the specified type.

Following are some built-in functions in C:


printf():
Used to print formatted output to the standard output stream (usually the
console).
scanf():
Used to read formatted input from the standard input stream (usually the
keyboard).
strcpy():
Copies the string pointed to by the source to the destination.
strcat():
Concatenates (appends) the string pointed to by the source to the destination.
strlen():
Returns the length of the string (number of characters excluding the null
terminator).
strcmp():
Compares two strings and returns an integer representing their lexicographical
order.
malloc():
Allocates memory dynamically on the heap.
calloc():
Allocates memory for an array of elements and initializes them to zero.
realloc():
Reallocates memory dynamically on the heap.
free():
Deallocates memory previously allocated by malloc(), calloc(), or realloc().
sqrt():
Calculates the square root of a given number.
pow():
Raises a number to the power of another number.
abs():
Returns the absolute value of an integer.
fabs():
Returns the absolute value of a floating-point number.
rand():
Generates a pseudo-random number.
Q2: write a program that will take marks as input and
calculate grades use switch for the calculation.

#include <stdio.h>
int main() {
int marks;
printf("Enter marks (out of 100): ");
scanf("%d", &marks);
switch (marks / 10) {
case 10:
case 9:
printf("Grade: A\n");
break;
case 8:
printf("Grade: B\n");
break;
case 7:
printf("Grade: C\n");
break;
case 6:
printf("Grade: D\n");
break;
case 5:
printf("Grade: E\n");
break;
default:
printf("Grade: F (Fail)\n");
break;
}
return 0;
}

You might also like