Freshers WisdomFreshers Wisdom
  • Latest Government Jobs
  • Sarkari Naukri
  • Private Jobs
  • Full Forms
  • Current Affairs
  • Interview
  • Public Holidays
  • Admit Cards
  • Results
Facebook Twitter Instagram Pinterest Tumblr
Thursday, March 30
Freshers WisdomFreshers Wisdom
Facebook Twitter Instagram Pinterest Tumblr
Join Telegram
  • Latest Government Jobs
  • Sarkari Naukri
  • Private Jobs
  • Full Forms
  • Current Affairs
  • Interview
  • Public Holidays
  • Admit Cards
  • Results
Freshers WisdomFreshers Wisdom
Advertisements

TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION

Freshers WisdomBy Freshers WisdomDecember 29, 2021
Facebook Twitter WhatsApp Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email Tumblr Reddit WhatsApp
Advertisements

TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION : Here are the Top 15 recently asked programs in various interviews like TCS, INFOSYS, WIPRO, ACCENTURE & other service-based companies :-

Advertisements
TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION
TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION

TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION

1.Prime Number Program:

Prime Number: A number that is greater than 1 & divided by 1 or itself

  1. #include<stdio.h>
  2. int main(){
  3. int n,i,m=0,flag=0;
  4. printf(“Enter the number to check prime:”);
  5. scanf(“%d”,&n);
  6. m=n/2;
  7. for(i=2;i<=m;i++)
  8. {
  9. if(n%i==0)
  10. {
  11. printf(“Number is not prime”);
  12. flag=1;
  13. break;
  14. }
  15. }
  16. if(flag==0)
  17. printf(“Number is prime”);
  18. return 0;
  19.  }

Output:

Enter the number to check prime:56
Number is not prime

Enter the number to check prime:23
Number is prime

2. Fibonacci Series:

Fibonacci: When next number is the sum of given 2 number then the series is called Fibonacci Series.

Example: 0, 1, 1, 2, 3, 5, 8….

  1. #include<stdio.h>  
  2. int main()
  3. {
  4.  int n1=0,n2=1,n3,i,number;
  5.  printf(“Enter the number of elements:”);
  6.  scanf(“%d”,&number);
  7.  printf(“\n%d %d”,n1,n2);//printing 0 and 1  
  8.  for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed  
  9.  {
  10.   n3=n1+n2;
  11.   printf(” %d”,n3);
  12.   n1=n2;
  13.   n2=n3;
  14.  }
  15.   return 0;
  16.  }

The above program is Fibonacci Series without Recursion

  1. #include<stdio.h>  
  2. void printFibonacci(int n){
  3.     static int n1=0,n2=1,n3;
  4.     if(n>0){
  5.          n3 = n1 + n2;
  6.          n1 = n2;
  7.          n2 = n3;
  8.          printf(“%d “,n3);
  9.          printFibonacci(n-1);
  10.     }
  11. }
  12. int main(){
  13.     int n;
  14.     printf(“Enter the number of elements: “);
  15.     scanf(“%d”,&n);
  16.     printf(“Fibonacci Series: “);
  17.     printf(“%d %d “,0,1);
  18.     printFibonacci(n-2);//n-2 because 2 numbers are already printed  
  19.   return 0;
  20.  }    ‘

The above Program is Fibonacci Series with Recursion

3.Factorial Number Program

Factorial: Factorial is represented as “5!” that means, 5*4*3*2*1

  1. #include<stdio.h>
  2. int main()
  3. {
  4.  int i,fact=1,number;
  5.  printf(“Enter a number: “);
  6.   scanf(“%d”,&number);
  7.     for(i=1;i<=number;i++){
  8.       fact=fact*i;
  9.   }
  10.   printf(“Factorial of %d is: %d”,number,fact);
  11. return 0;
  12. }

4. Pattern Program:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5.     int i, j, rows, k = 0;
  6.     printf (” Enter a number to define the rows: \n”);
  7.     scanf (“%d”, &rows);
  8.     for ( i =1; i <= rows; i++)
  9.     {
  10.         for ( j = 1; j <= rows – i; j++)
  11.         {
  12.             printf (”  “);
  13.         }
  14.         // use for loop where k is less than equal to (2 * i -1)
  15.         for ( k = 1; k <= ( 2 * i – 1); k++)
  16.         {
  17.             printf (“* “); // print the Star
  18.         }
  19.         printf (“\n”);
  20.     }
  21.     getch();
  22. }

Output:

*

*         *

*      *        *

5. Sum of Digits in a Program:

  1. #include<stdio.h>
  2.  int main()
  3. {
  4. int n,sum=0,m;
  5. printf(“Enter a number:”);
  6. scanf(“%d”,&n);
  7. while(n>0)
  8. {
  9. m=n%10;
  10. sum=sum+m;
  11. n=n/10;
  12. }
  13. printf(“Sum is=%d”,sum);
  14. return 0;
  15. }

Output:

Enter a number:654

Sum is=15

Enter a number:123

Sum is=6

6. Given Number is Palindrome Number or not:

Palindrome: Palindrome is a number that is same even after reverse.

Example: 121, 34543

  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: 

Given Number: 151

The Number is Palindrome

7. Given Number is Leap Year is not?

#include <stdio.h>

int main()
{    
    int year;      
    printf("Enter a year to check if it is a leap year\n");
    scanf("%d", &year);
          
    if ( year%400 == 0)      
    printf("%d is a leap year.\n", year);  
        
    else if ( year%100 == 0)      
    printf("%d is not a leap year.\n", year); 
         
    else if ( year%4 == 0 )      
    printf("%d is a leap year.\n", year);
    
    else      
    printf("%d is not a leap year.\n", year);      
    
    return 0;    
}

Output of program:

Enter a year to check it is a leap year or not

2012

2012 is not a leap year

8. Given Number is Armstrong Number or Not?

Armstrong Number: It is a number that is sum of cubes of its number.

For example take a number: 371

Logic:

  1. 371 = (3*3*3)+(7*7*7)+(1*1*1)
  2. where:
  3. (3*3*3)=27
  4. (7*7*7)=343
  5. (1*1*1)=1
  6. So:
  7. 27+343+1=371

Program:

#include<stdio.h>

Advertisements

 int main()

{

int n,r,sum=0,temp;

printf(“enter the number=”);

scanf(“%d”,&n);

temp=n;

while(n>0)

{

r=n%10;

sum=sum+(r*r*r);

n=n/10;

}

if(temp==sum)

printf(“armstrong  number “);

else

printf(“not armstrong number”);

return 0;

}

9. Given Number is Strong or Not:

Strong Number: If sum of the factorial of the individual digits is equal to the number.

Program:

  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int n;
  5.     int sum=0;
  6.     printf(“Enter a number”);
  7.     scanf(“%d”,&n);
  8.     int k=n;
  9.     int r;
  10.     while(k!=0)
  11.     {
  12.         r=k%10;
  13.         int f=fact(r);
  14.         k=k/10;
  15.         sum=sum+f;
  16.     }
  17.     if(sum==n)
  18.     {
  19.         printf(“\nNumber is a strong”);
  20.     }
  21.     else
  22.     {
  23.         printf(“\nNumber is not a strong”);
  24.     }
  25.     return 0;
  26. }
  27. int fact(int r)
  28. {
  29.     int mul=1;
  30.     for(int i=1;i<=r;i++)
  31.     {
  32.         mul=mul*i;
  33.     }
  34.     return mul;
  35. }

10. Given Number is Perfect Number or not?

Perfect Number: 

  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int i = 1, num, Sum = 0;
  6. printf(” Enter any number to check Perfect Number \n”);
  7. scanf(“%d”, &num);
  8. while(i < num )
  9.                      {
  10.                                if(num % i == 0)
  11.                                Sum = Sum + i;
  12.                                i++;
  13.                      }
  14.            if(Sum == num)
  15.                   printf(“\n %d is Perfect Number”, num);
  16.            else
  17.            printf(“\n %d is not a Perfect Number”, num);
  18. getch();
  19. }

11. Swapping of 2 numbers without using the 3rd Number:

  1. #include<stdio.h>
  2.  int main()
  3. {
  4. int a=10, b=20;
  5. printf(“Before swap a=%d b=%d”,a,b);
  6. a=a+b;//a=30 (10+20)  
  7. b=a-b;//b=10 (30-20)  
  8. a=a-b;//a=20 (30-10)  
  9. printf(“\nAfter swap a=%d b=%d”,a,b);
  10. return 0;
  11. }

12. Harshad Number for TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION:

If a number is divisible by the sum of its digits then it will be known as a Harshad Number.

For example:

156 is divisible by the sum (12) of its digits (1, 5, 6 ).

  1. #include <stdio.h>  
  2. int main()
  3. {
  4.     int num = 156;
  5.     int rem = 0, sum = 0, n;
  6.     //Make a copy of num and store it in variable n  
  7.     n = num;
  8.     //Calculates sum of digits  
  9.     while(num > 0){
  10.         rem = num%10;
  11.         sum = sum + rem;
  12.         num = num/10;
  13.     }
  14.     //Checks whether number is divisible by sum of digits  
  15.     if(n%sum == 0)
  16.         printf(“%d is a harshad number”, n);
  17.     else
  18.         printf(“%d is not a harshad number”, n);
  19.     return 0;
  20. }

13. Program to check whether a given number is EVEN or ODD for TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION

#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;
}

14. Reversing of Numbers For TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION:

  1. #include<stdio.h>
  2.  int main()
  3. {
  4. int n, reverse=0, rem;
  5. printf(“Enter a number: “);
  6.   scanf(“%d”, &n);
  7.   while(n!=0)
  8.   {
  9.      rem=n%10;
  10.      reverse=reverse*10+rem;
  11.      n/=10;
  12.   }
  13.   printf(“Reversed Number: %d”,reverse);
  14. return 0;
  15. }

15. Program to convert Decimal to Binary:

  1. #include<stdio.h>  
  2. #include<stdlib.h>
  3. int main(){
  4. int a[10],n,i;
  5. system (“cls”);
  6. printf(“Enter the number to convert: “);
  7. scanf(“%d”,&n);
  8. for(i=0;n>0;i++)
  9. {
  10. a[i]=n%2;
  11. n=n/2;
  12. }
  13. printf(“\nBinary of Given Number is=”);
  14. for(i=i-1;i>=0;i–)
  15. {
  16. printf(“%d”,a[i]);
  17. }
  18. return 0;
  19. }

Output:

Enter the number to convert: 5

Binary of Given Number is=101

TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION

This program can be written in C/JAVA/PYTHON (TOP 15 IMPORTANT PROGRAMS FOR INTERVIEWS WITH SOLUTION)

Join Telegram Group: Click Here

Latest Government Job Notification

Advertisements
Share. Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp Email Reddit

Related Posts

IUST Kashmir recruitment 2023: Apply for 21 vacancies of Assistant Professors

January 15, 2023By Freshers Wisdom

KGBV Bihar Recruitment 2023 – Apply Online For 3976 Teaching Posts,Notification out

January 9, 2023By Freshers Wisdom

Pondicherry University Recruitment 2022 Out – Apply for 76 Administrative Vacancies, Eligible candidates

September 24, 2022By Freshers Wisdom

IOCL Apprentice Jobs Notification 2022 – Apply for 1535 Posts, Eligibility Criteria

September 24, 2022By Freshers Wisdom

SECL Recruitment 2022 – Apply For 130 Senior Medical Executive Posts, Eligibility Criteria

September 21, 2022By Freshers Wisdom

District Education Officer Dhanbad Recruitment 2022 – Apply for 182 Posts, Application Form

September 21, 2022By Freshers Wisdom

Leave A Reply Cancel Reply

Stay Connected
  • Facebook 10.1K
  • Twitter 1.7K
  • Pinterest 1.9K
  • Instagram 5.4K
Latest Posts

Yantra India Limited Recruitment 2023 Notification Out for 5450 Trade Apprentice Posts

January 9, 2023

IOCL Apprentice Jobs Notification 2022 – Apply for 1535 Posts, Eligibility Criteria

September 24, 2022

SECL Recruitment 2022 – Apply For 130 Senior Medical Executive Posts, Eligibility Criteria

September 21, 2022

IGIMS Recruitment 2022 – Apply For 70 Junior Resident Posts |Apply Online | Notification

September 15, 2022

TSPSC Extension Officer Jobs 2022 – Apply For 181 Posts, Last Date 29th September 2022

September 8, 2022
- Advertisement -
Current Affairs

Top Current Affairs 11th December 2021 at Freshers Wisdom

December 11, 2021

Top Current Affairs 9th December 2021 at Freshers Wisdom

December 9, 2021

Top Current Affairs 8th December 2021 at Freshers Wisdom

December 8, 2021

Top Current Affairs 7th December 2021 at Freshers Wisdom

December 7, 2021

Top Current Affairs 6th December 2021 at Freshers Wisdom

December 6, 2021
- Advertisement -

Job Categories

  • Central Govt Jobs
  • State Govt Jobs
  • Private Jobs
  • Engineering Jobs
  • Bank Jobs
  • Railway Jobs
  • Nursing Jobs
  • Teaching Jobs
  • Defence Jobs
  • State Police Jobs
  • Court Jobs
  • SSC Jobs
  • UPSC Jobs
  • State PSCs
  • Maharatna PSUs
  • Mini Ratna
Copyright © Freshers Wisdom - 2023
  • About
  • Privacy Policy
  • Disclaimers
  • Contact

Type above and press Enter to search. Press Esc to cancel.