Sunday, August 30, 2015

Interview Programs on C introduction (Data types and operators)

2015 & 2016 Batch Freshers Registration Link

JOIN MY FACEBOOK GROUP FOR UPDATES 

Interview Programs on C introduction (Data types and operators)

Swapping of two numbers with third variable

main()
{
          int num1,num2,temp;
          printf(“ Enter two numbers “);
          scanf(“ %d %d”,&num1,&num2);

          temp=num1;
          num1=num2;
          num2= temp;

          printf(“Two numbers after swapping are %d and %d”, num1, num2);
}

Swapping of two numbers without third variable

main()
{
          int num1,num2;
          printf(“ Enter two numbers “);
          scanf(“ %d %d”,&num1,&num2);

          num1 = num1 + num2;
          num2=num1 – num2;
          num1= num1 – num2;

          printf(“Two numbers after swapping are %d and %d”, num1, num2);
}


C Program to Find Quotient and Remainder of Two Integers Entered by User

main()
{
          int num1,num2,rem, quot;
          printf(“ Enter two numbers “);
          scanf(“ %d %d”,&num1,&num2);

          rem = num1% num2;
          quot = num1 / num2;
         

          printf(“Remainder and quotient are %d and %d”, rem, quot);
}


C Program to Calculate Sum of Natural Numbers

main()
{
          int num,sum=0;
          printf(“ Enter a number “);
          scanf(“ %d ”,&num);

          sum= (num * (num +1))/2;
          printf(“ Sum of Natural numbers upto %d is %d”, num, sum);
}


C Program to Check Whether a Number is Even or Odd with conditional operator

main()
{
          int num;
          printf(“ Enter a number “);
          scanf(“ %d ”,&num);

          ((num%2)==0)?printf(“Even”):printf(“Odd);
}

C Program to Find the Largest Number between two Numbers using conditional operator

main()
{
          int num1,num2,large;
          printf(“ Enter two numbers “);
          scanf(“ %d %d ”,&num1,&num2);

          large= (num1 > num2)?num1:num2;
          printf( “Largest number is %d”,large);
}

C Program to Find the Smallest Number between two numbers using conditional operator


main()
{
          int num1,num2,small;
          printf(“ Enter two numbers “);
          scanf(“ %d %d ”,&num1,&num2);
         
          small= (num1 < num2)?num1:num2;
          printf( “Smallest  number is %d”,small);
}


C Program to Find the Largest Number among Three Numbers using conditional operator

main()
{
          int num1,num2,num3,large;
          printf(“ Enter three  numbers “);
          scanf(“ %d %d %d”,&num1,&num2,&num3);

          large= (num1 > num2)?num1:num2;
          large=(large > num3)? large: num3;
          printf( “Largest number is %d”,large);
}


C Program to Find the Smallest Number among Three Numbers using conditional operator

main()
{
          int num1,num2,num3,small;
          printf(“ Enter three  numbers “);
          scanf(“ %d %d %d”,&num1,&num2,&num3);

          small= (num1 < num2)?num1:num2;
          small=(small < num3)? small: num3;
          printf( “smallest number is %d”,small);
}


C Program to Find the Middle Number among Three Numbers using conditional operator

C program to arrange three numbers in ascending order using conditional operator

C program to arrange three numbers in Descending order using conditional operator

C Program to Check Leap Year using conditional operator

main()
{
          int year;
          printf(“Enter year”);
          scanf(“%d”,&year);

          (year%4==0 && (year % 100 !=0 || year % 400 ==0))?printf(“Leap year”):printf(“not a leap year);


}

Contact Form

Name

Email *

Message *