Header Ads Widget

C

 1. Shut Down Computer


#include <stdio.h>
#include <stdlib.h>

int main( )
{
     system('C:\\WINDOWS\\System32\\shutdown /s');

     return 0;
}


Warning :- This will shutdown your pc. If you want to try this code, first close all the running tab and then run this program.



2. Check Leap Year


#include <stdio.h>
int main()
{
    int y;

    printf("Enter year: ");
    scanf("%d",&y);

    if(y % 4 == 0)
    {
    //Nested if else
        if( y % 100 == 0)
        {
            if ( y % 400 == 0)
                printf("%d is a Leap Year", y);
            else
                printf("%d is not a Leap Year", y);
        }
        else
            printf("%d is a Leap Year", y );
    }
    else
        printf("%d is not a Leap Year", y);

    return 0;
}


Output :-


Enter year: 2021

2021 is not a Leap Year



3. Get Current Date and Time


#include<stdio.h>
#include<time.h>

int main()
{
    printf("\n\n\t\tAnonymous\n\n\n");

    time_t t;   // not a primitive datatype
    time(&t);

    printf("\nThis program has been writeen at (date and time): %s", ctime(&t));

    return 0;
}


Output :-


Anonymous


This program has been writeen at (date and time): Sat Apr 24 19:58:46 2021



4. Calculate Student Grade


/* C program to Find Grade of a Student */
 
#include <stdio.h>
 
int main()
{
    int english, chemistry, computers, physics, maths; 
    float Total, Percentage;
 
    printf(" Please Enter the Five Subjects Marks : \n");
    scanf("%d%d%d%d%d", &english, &chemistry, &computers, &physics, &maths);
 
    Total = english + chemistry + computers + physics + maths;
    Percentage = (Total / 500) * 100;
 
    printf(" Total Marks = %.2f\n", Total);
    printf(" Marks Percentage = %.2f", Percentage);
    
    if(Percentage >= 90)
    {
    printf("\n Grade A");
}
else if(Percentage >= 80)
    {
    printf("\n Grade B");
}
else if(Percentage >= 70)
    {
    printf("\n Grade C");
}
else if(Percentage >= 60)
    {
    printf("\n Grade D");
}
else if(Percentage >= 40)
    {
    printf("\n Grade E");
}
else 
    {
    printf("\n Fail");
    return 0;
}


Output :-


Please Enter the Five Subjects Marks : 
90
85
86
76
75
Total Marks = 412.00
 Marks Percentage = 82.40
 Grade B





Post a Comment

0 Comments