Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

C OPERATORS PRECEDENCE AND ASSOCIATIVITY

Rank

Operator

Explanation

Associativity

1

()

[]

.

->

Parenthesis

Square brackets

Direct Member selection

Indirect Member selection

 

Left to right

2

++

--

!

~

(type)

&

*

Increment

Decrement

Logical negation

Bitwise complement

Type casting

Address

Pointer reference

Right to left

3

*

/

%

Multiplication

Division

Remainder

Left to right

4

+

-

Addition

Subtraction

Left to right

5

<< 

>> 

Left shift

Right shift

Left to right

6

< 

<=

> 

>=

Less than

Less than or equal to

Greater than

Greater than or equal to

Left to right

7

==

!=

Equal to

Not equal to

Left to right

8

&

 

Bitwise AND

 

Left to right

9

^

 

Bitwise exclusive OR

 

Left to right

10

|

Bitwise Inclusive OR

Left to right

11

&&

Logical AND

Left to right

12

||

Logical OR

Left to right

13

?:

Ternary operator

Right to Left

14

=

*=

/=

%=

+=

-=

&=

^=

|=

<<=

>>=

Assignment

Multiplication assignment

Division assignment

Modulus assignment

Addition assignment

Subtraction assignment

Bitwise And assignment

Bitwise inclusive assignment

Bitwise exclusive assignment

Bitwise shift left assignment

Bitwise shift right assignment

Right to left

15

,

Comma

Left to right

 

C program using all 32 keywords available in ANSCII

Question:WAP in c using all 32 keyword available in ANSCII

solution

#include ⁢stdio.h>
#include ⁢stdlib.h>
const signed sub = 5;
typedef enum number {student1, student2, student3};
union Job {
     unsigned int  Tyear;
     volatile int Lyear;
} T;
extern float grade=3.0;
 struct
{
    char fn[12],ln[8];
    short int sn,cpl,egp,mat,tsm,phy,t;
     float per;
}student[3];
static long int i=0;
int main()
{
   auto int choice;
    for(i=0;i<3;i++)
    {
        printf("Enter student %d first name:",i+1);
        scanf("%s",student[i].fn);
        printf("Enter student %d second name:",i+1);
        scanf("%s",student[i].ln);
        printf("Enter student number:");
        scanf("%d",&student[i].sn);
        printf("Enter CPL101 marks:");
        scanf("%d",&student[i].cpl);
        printf("Enter EGP101 marks:");
        scanf("%d",&student[i].egp);
        printf("Enter MAT102 marks:");
        scanf("%d",&student[i].mat);
        printf("Enter TSM101 marks:");
        scanf("%d",&student[i].tsm);
        printf("Enter PHY101 marks:");
        scanf("%d",&student[i].phy);
        student[i].t = student[i].phy+student[i].tsm+student[i].mat+student[i].egp+student[i].cpl;
        student[i].per=student[i].t/sub;
    }
    retry:
    printf("Press\n 1: to see Highest Percentage\n 2:to see overall grading\n 3:to print result\n" );
    scanf("%d",&choice);
    switch(choice)
    {
        case 1: printf("the Highest percentage is:");
                topper();
                break;
        case 2:printf("Analysis:");
                news();
                break;
        case 3:printf("Printing result:");
                printingresult();
                break;
        default: printf("Wrong Choice\n");
                goto retry;
    }
    return 0;

}
void printingresult()
{
     printf("\nstd.no        name       cpl        phy       mat       egp             tsm           total           per\n");
     i=0;
        do
    {
        printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t\t%f\n",student[i].sn,student[i].fn,student[i].ln,student[i].cpl,student[i].phy,student[i].mat,student[i].egp,student[i].tsm,student[i].t,student[i].per);
                i++;
    }while(i&lt3);
}
void topper()
{
    register double max;
    for(i =student1;i&lt=student3;i++)
    {
        if(max>student[i].per)
        {
            continue;
        }
        else
        {
                 max = student[i].per;
        }
    }
    printf("%4f",max);
}
void news()
{
    T.Lyear=2020;
    printf("Result in year: %d",T.Lyear);
    printf("\nGrade last year: %f",grade);
    T.Tyear=2021;
    printf("\nResult this year %d",T.Tyear);
    grade = student[0].per+student[1].per+student[2].per;
    printf("\nOverall Grade:%f",(grade/3));

}

output

Posted in

Structure in C-1

Question: Write a program in C using struct for displaying results in order for 3 students.The program used include name,marks in 6 subjects,total and average. it should print result in table form

#include <stdio.h>
#include <stdlib.h>
struct
{
    char fn[12],ln[8];
    int sn,cpl,che,mat,egp,phy,acs,t;
    float per;
}student[2];
int main()
{
    int i=0,tmp,j=0;
    for(i=0;i<3;i++)
    {
        printf("Enter student %d first name:",i+1);
        scanf("%s",student[i].fn);
        printf("Enter student %d second name:",i+1);
        scanf("%s",student[i].ln);
        printf("Enter student number:");
        scanf("%d",&student[i].sn);
        printf("Enter CPL101 marks:");
        scanf("%d",&student[i].cpl);
        printf("Enter CHE101 marks:");
        scanf("%d",&student[i].che);
        printf("Enter MAT101 marks:");
        scanf("%d",&student[i].mat);
        printf("Enter EGP101 marks:");
        scanf("%d",&student[i].egp);
        printf("Enter PHY101 marks:");
        scanf("%d",&student[i].phy);
        printf("Enter ACS101 marks :");
        scanf("%d",&student[i].acs);
        student[i].t = student[i].acs+student[i].phy+student[i].mat+student[i].che+student[i].egp+student[i].cpl;
        student[i].per=student[i].t/6;
    }
       for(i=0; i<3; i++)
    {
        for(j=i+1; j<=3; j++)
        {
            if(student[i].per <student[j].per)
            {
                tmp = student[i].per;
                student[i].per = student[j].per;
               student[j].per = tmp;
            }
        }
    }
    printf("\nstd.no        name       cpl        che        mat       egp       phy        acs           total           per\n");
        for(i=0; i<3; i++)
    {
        printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%f\n",student[i].sn,student[i].fn,student[i].ln,student[i].cpl,student[i].che,student[i].mat,student[i].egp,student[i].phy,student[i].acs,student[i].t,student[i].per);


    }
}

Output

Posted in