C programming important question PPS 1st and 2nd-semester AKTU exam

Que.1: Any year is input through the keyboard. Write a program to determine whether the year is a Leap year or not.

Ans:–  

#include<stdio.h>

#include<conio.h>
main()
{
     int yr;
 

     printf(“nEnter any year:”);

     scanf(“%d”,&yr);
 
     if(yr%400==0)||(yr%100!=0&& yr%4==0))
     printf(“n%d is a leap  year.”,yr);
     else
     printf(“n%d is not a leap year.”,yr);
    getch();
     return 0;
   }
 
 

Output:

Enter any year: 2012

2012 is a leap year

Enter any year:2013

 2013 is not a leap year

 
 

Que.2:A five-digit number is entered through the keyboard. Write a program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not.

Ans. 

    #include<stdio.h>

   #include<conio.h>
    void main()
   {
     int n,a,b;
    long int revnum = 0;
    clrscr();
    printf(“n Enter a five digit number (less than 32767):”);
    scanf(“%d”,&n);
    a=n%10;
    n=n/10;
    revnum = revnum+a*10000;
    a=n%10;
    n=n/10;
    revnum = revnum+a*1000;
    a=n%10;
    n=n/10;
    revnum = revnum+a*100;
    a=n%10;
    n=n/10;
    revnum = revnum+a*10;
    a=n%10;
    revnum = revnum+a;
    printf(“The reversed number is %1d”,revnum);
    If(n==revnum)
{
   printf(“Number are equal”);
}
   else
{
   printf(“Numbers are not equal”);
}
  getch();
}
  

Leave a Comment