Ppsc ct 1 and ct2

SET- NO - 4 

ASSIGNMENT - 1

1.) what is an expression ? write the priority and associaty of different arthimetic operators

in c ? evaluate 2+4*5/2-2/4+2%5?

Go down u will find the answer at set -2 assignment -1  👇👇👇👇👇

2). what is ascii value and unicode ? explain how they are used in c language ?

In C programming, a character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself. This integer value is the ASCII code of the character.

For example, the ASCII value of 'A' is 65.

What this means is that, if you assign 'A' to a character variable, 65 is stored in the variable rather than 'A' itself.

example

#include <stdio.h>

int main() {  
    char c;
    printf("Enter a character: ");
    scanf("%c", &c);  
    
    // %d displays the integer value of a character
    // %c displays the actual character
    printf("ASCII value of %c = %d", c, c);
    
    return 0;
}

3).illustrate input and output stream in c with prinntf and scanf  how to detech error during The data input ?

Go down u will find the answer at set -3 assignment -1  👇👇👇👇👇

SET- NO -III

ASSIGNMENT - 1

1). WHAT IS SCOPE OF VARIABLE ? EXPLAIN BLOCK SCOPE , FUNCTION SCOPE, PROGRAM SCOPE AND FILE SCOPE 

A variable's scope is the context in which can be used. It defines “how long the variable lives,” or “where the variable exists.”

 A variable with limited scope, as in the execution of a function, is called a local variable.

Function Scope: A Function scope begins at the opening of the function and ends with the closing of it. Function scope is applicable to labels only. A label declared is used as a target to go to the statement and both goto and label statement must be in the same function.

A block scope is the area within if, switch conditions or for and while loops. Generally speaking, whenever you see {curly brackets}, it is a block. 

File scope is varibale can be accessed with in the file 

2).illustrate input and output stream in c with prinntf and scanf  how to detech error during The data input ?

 printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).

printf() function

The printf() function is used for output. It prints the given statement to the console.

The syntax of printf() function is given below:

  1. printf("format string",argument_list);  

The format string can be %d (integer), %c (character), %s (string), %f (float) etc.


scanf() function

The scanf() function is used for input. It reads the input data from the console.

  1. scanf("format string",argument_list);  

3. how are expression evaluted in c . explain the role of precedence and associaty in it give an example ?

Go down u will find the answer at set -2 assignment -1  👇👇👇👇👇



SET NO -II

ASSIGNMENT-1

3) WHAT  IS CONSTANT ? EXPLAIN DIFFERENTE TYPES OF CONSTANTS AVALIBLE IN C WITH EXAMPLES ?

.

A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc.

There are different types of constants in C programming.

List of Constants in C

ConstantExample
Decimal Constant10, 20, 450 etc.
Real or Floating-point Constant10.3, 20.2, 450.6 etc.
Octal Constant021, 033, 046 etc.
Hexadecimal Constant0x2a, 0x7b, 0xaa etc.
Character Constant'a', 'b', 'x' etc.
String Constant"c", "c program", "c in javatpoint" etc.
2.  HOW ARE EXPRESSION EVALUATED IN C ? EXPLAIN THE ROLE OF PREDENCE AND ASSOICATIVITY IN IT  GIVE EXAMPLE ?
Infix Notation: Operators are written between the operands they operate on, e.g. 3 + 4.
Prefix Notation: Operators are written before the operands, e.g + 3 4
Postfix Notation: Operators are written after operands.
Infix Expressions are harder for Computers to evaluate because of the additional work needed to decide precedence. Infix notation is how expressions are written and recognized by humans and, generally, input to programs. Given that they are harder to evaluate, they are generally converted to one of the two remaining forms. A very well known algorithm for converting an infix notation to a postfix notation is Shunting Yard Algorithm by Edgar Dijkstra. This algorithm takes as input an Infix Expression and produces a queue that has this expression converted to postfix notation. The same algorithm can be modified so that it outputs the result of the evaluation of expression instead of a queue. The trick is using two stacks instead of one, one for operands, and one for operators.


1). The difference between Type casting and Type conversion which are given below:


set-4

assignment 2
1. using switch write a program thhat finds the day of given number
/** * C program to print day of week using switch case */ #include <stdio.h> int main() { int week; /* Input week number from user */ printf("Enter week number(1-7): "); scanf("%d", &week); switch(week) { case 1: printf("Monday"); break; case 2: printf("Tuesday"); break; case 3: printf("Wednesday"); break; case 4: printf("Thursday"); break; case 5: printf("Friday"); break; case 6: printf("Saturday"); break; case 7: printf("Sunday"); break; default: printf("Invalid input! Please enter week number between 1-7."); } return 0; }

2. write program to print below using loopas
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include <stdio.h>
int main() {
   int i, j, rows;
   printf("Enter the number of rows: ");
   scanf("%d", &rows);
   for (i = 1; i <= rows; ++i) {
      for (j = 1; j <= i; ++j) {
         printf("%d ", j);
      }
      printf("\n");
   }
   return 0;
}
3. find odd and even number
#include <stdio.h>
int main() {
    int num;
    printf("Enter an integer: ");
    scanf("%d", &num);

    // true if num is perfectly divisible by 2
    if(num % 2 == 0)
        printf("%d is even.", num);
    else
        printf("%d is odd.", num);
    
    return 0;
}




set-3
assignment -2 
1.write a c program to determine charcter entered by user

#include<stdio.h>
int main(){
   char ch;
   printf("enter a character:");
   scanf("%c",&ch);
   if(ch >= 65 && ch <= 90)
      printf("Upper Case Letter");
   else if(ch >= 97 && ch <= 122)
      printf("Lower Case letter");
   else if(ch >= 48 && ch <= 57)
      printf("Number");
   else
      printf("Symbol");
   return 0;
}

2. write a program to destrome nested if else statments

nested-if in C/C++

A nested if in C is an if statement that is the target of another if statement. Nested if statements mean an if statement inside another if statement. Yes, both C and C++ allow us to nested if statements within if statements, i.e, we can place an if statement inside another if statement. 
Syntax: 
 

if (condition1) 
{
   // Executes when condition1 is true
   if (condition2) 
   {
      // Executes when condition2 is true
   }
}

Flowchart 
 



nested-if

Example: 
 

// C program to illustrate nested-if statement
#include <stdio.h>
 
int main() {
    int i = 10;
 
    if (i == 10)
    {
        // First if statement
        if (i < 15)
           printf("i is smaller than 15\n");
 
        // Nested - if statement
        // Will only be executed if statement above
        // is true
        if (i < 12)
            printf("i is smaller than 12 too\n");
        else
            printf("i is greater than 15");
    }
 
    return 0;
}
Output: 
i is smaller than 15
i is smaller than 12 too

set-2

assignment-2
3. write a prgram to print palidrome or not ?

  1. #include<stdio.h>  
  2. int main()    
  3. {    
  4. int n,r,sum=0,temp;    
  5. printf("enter the number=");    
  6. scanf("%d",&n);    
  7. temp=n;    
  8. while(n>0)    
  9. {    
  10. r=n%10;    
  11. sum=(sum*10)+r;    
  12. n=n/10;    
  13. }    
  14. if(temp==sum)    
  15. printf("palindrome number ");    
  16. else    
  17. printf("not palindrome");   
  18. return 0;  
  19. }   

Output:

enter the number=151
palindrome  number

enter the number=5621
not palindrome  number

2. write a program to print average of number  entered by the user ?

include <stdio.h>
int main() {
    int n, i;
    float num[100], sum = 0.0, avg;

    printf("Enter the numbers of elements: ");
    scanf("%d", &n);

    while (n > 100 || n < 1) {
        printf("Error! number should in range of (1 to 100).\n");
        printf("Enter the number again: ");
        scanf("%d", &n);
    }

    for (i = 0; i < n; ++i) {
        printf("%d. Enter number: ", i + 1);
        scanf("%f", &num[i]);
        sum += num[i];
    }

    avg = sum / n;
    printf("Average = %.2f", avg);
    return 0;
}


1. write a program to determine the wheter an entered charcter is vowel or not ?

include <ctype.h>
#include <stdio.h>

int main() {
   char c;
   int lowercase_vowel, uppercase_vowel;
   printf("Enter an alphabet: ");
   scanf("%c", &c);
   // evaluates to 1 if variable c is a lowercase vowel
   lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

   // evaluates to 1 if variable c is a uppercase vowel
   uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

   // Show error message if c is not an alphabet
   if (!isalpha(c))
      printf("Error! Non-alphabetic character.");
   else if (lowercase_vowel || uppercase_vowel)
      printf("%c is a vowel.", c);
   else
      printf("%c is a consonant.", c);

   return 0;
}
Previous Post Next Post