Find odd or even using conditional operator
#include<stdio.h>
main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
n%2 == 0 ? printf("Even number\n") : printf("Odd number\n");
return 0;
}
#include<stdio.h>
main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
n%2 == 0 ? printf("Even number\n") : printf("Odd number\n");
return 0;
}
c program to check whether input alphabet is a vowel or not
This code checks whether an input alphabet is a vowel or not. Both lower-case and upper-case are checked.
C programming code
#include <stdio.h>
main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
if (ch == 'a' ch == 'A' ch == 'e' ch == 'E' ch == 'i' ch == 'I' ch =='o' ch=='O' ch == 'u' || ch == 'U')
printf("%c is a vowel.\n", ch);
else
printf("%c is not a vowel.\n", ch);
return 0;
}
Output:
a
a is vowel
This code checks whether an input alphabet is a vowel or not. Both lower-case and upper-case are checked.
C programming code
#include <stdio.h>
main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
if (ch == 'a'
printf("%c is a vowel.\n", ch);
else
printf("%c is not a vowel.\n", ch);
return 0;
}
Output:
a
a is vowel
Check vowel using switch statement
#include <stdio.h>
main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is not a vowel.\n", ch);
}
return 0;
}
#include <stdio.h>
main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is not a vowel.\n", ch);
}
return 0;
}
Function to check vowel
int check_vowel(char a)
{
if (a >= 'A' && a <= 'Z')
a = a + 'a' - 'A'; /* Converting to lower case or use a = a + 32 */
if (a == 'a' a == 'e' a == 'i' a == 'o' a == 'u')
return 1;
return 0;
}
int check_vowel(char a)
{
if (a >= 'A' && a <= 'Z')
a = a + 'a' - 'A'; /* Converting to lower case or use a = a + 32 */
if (a == 'a'
return 1;
return 0;
}
c program to check leap year
c program to check leap year: c code to check leap year, year will be entered by the user. Please read the leap year article before reading the code, it will help you to understand the program.
C programming code
#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;
}
c program to check leap year: c code to check leap year, year will be entered by the user. Please read the leap year article before reading the code, it will help you to understand the program.
C programming code
#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;
}
add digits of number in c
C program to add digits of a number: Here we are using modulus operator(%) to extract individual digits of number and adding them.
C programming code
#include <stdio.h>
main()
{
int n, sum = 0, remainder;
printf("Enter an integer\n");
scanf("%d",&n);
while(n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
printf("Sum of digits of entered number = %d\n",sum);
return 0;
}
C program to add digits of a number: Here we are using modulus operator(%) to extract individual digits of number and adding them.
C programming code
#include <stdio.h>
main()
{
int n, sum = 0, remainder;
printf("Enter an integer\n");
scanf("%d",&n);
while(n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
printf("Sum of digits of entered number = %d\n",sum);
return 0;
}
Add digits using recursion
#include <stdio.h>
int add_digits(int);
int main() {
int n, result;
scanf("%d", &n);
result = add_digits(n);
printf("%d\n", result);
return 0;
}
int add_digits(int n) {
static int sum = 0;
if (n == 0) {
return 0;
}
sum = n%10 + add_digits(n/10);
return sum;
}
#include <stdio.h>
int add_digits(int);
int main() {
int n, result;
scanf("%d", &n);
result = add_digits(n);
printf("%d\n", result);
return 0;
}
int add_digits(int n) {
static int sum = 0;
if (n == 0) {
return 0;
}
sum = n%10 + add_digits(n/10);
return sum;
}
Factorial program in c using for loop
: Here we find factorial using for loop.
#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;
printf("Factorial of %d = %d\n", n, fact);
return 0;
}
: Here we find factorial using for loop.
#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;
printf("Factorial of %d = %d\n", n, fact);
return 0;
}
Factorial program in c using function
#include <stdio.h>
long factorial(int);
int main()
{
int number;
long fact = 1;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &number);
printf("%d! = %ld\n", number, factorial(number));
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result * c;
return result;
}
#include <stdio.h>
long factorial(int);
int main()
{
int number;
long fact = 1;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &number);
printf("%d! = %ld\n", number, factorial(number));
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result * c;
return result;
}
Factorial program in c using recursion
#include<stdio.h>
long factorial(int);
int main()
{
int num;
long f;
printf("Enter a number to find factorial\n");
scanf("%d", &num);
if (num < 0)
printf("Negative numbers are not allowed.\n");
else
{
f = factorial(num);
printf("%d! = %ld\n", num, f);
}
return 0;
}
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
#include<stdio.h>
long factorial(int);
int main()
{
int num;
long f;
printf("Enter a number to find factorial\n");
scanf("%d", &num);
if (num < 0)
printf("Negative numbers are not allowed.\n");
else
{
f = factorial(num);
printf("%d! = %ld\n", num, f);
}
return 0;
}
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
C programming code to find hcf and lcm
#include <stdio.h>
int main() {
int a, b, x, y, t, gcd, lcm;
printf("Enter two integers\n");
scanf("%d%d", &x, &y);
a = x;
b = y;
while (b != 0) {
t = b;
b = a % b;
a = t;
}
gcd = a;
lcm = (x*y)/gcd;
printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
return 0;
}
#include <stdio.h>
int main() {
int a, b, x, y, t, gcd, lcm;
printf("Enter two integers\n");
scanf("%d%d", &x, &y);
a = x;
b = y;
while (b != 0) {
t = b;
b = a % b;
a = t;
}
gcd = a;
lcm = (x*y)/gcd;
printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
return 0;
}
C program to find hcf and lcm using recursion
#include <stdio.h>
long gcd(long, long);
int main() {
long x, y, hcf, lcm;
printf("Enter two integers\n");
scanf("%ld%ld", &x, &y);
hcf = gcd(x, y);
lcm = (x*y)/hcf;
printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);
return 0;
}
long gcd(long a, long b) {
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
#include <stdio.h>
long gcd(long, long);
int main() {
long x, y, hcf, lcm;
printf("Enter two integers\n");
scanf("%ld%ld", &x, &y);
hcf = gcd(x, y);
lcm = (x*y)/hcf;
printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);
return 0;
}
long gcd(long a, long b) {
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
C program to find hcf and lcm using function
#include <stdio.h>
long gcd(long, long);
int main() {
long x, y, hcf, lcm;
printf("Enter two integers\n");
scanf("%ld%ld", &x, &y);
hcf = gcd(x, y);
lcm = (x*y)/hcf;
printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);
return 0;
}
long gcd(long x, long y) {
if (x == 0) {
return y;
}
while (y != 0) {
if (x > y) {
x = x - y;
}
else {
y = y - x;
}
}
return x;
}
#include <stdio.h>
long gcd(long, long);
int main() {
long x, y, hcf, lcm;
printf("Enter two integers\n");
scanf("%ld%ld", &x, &y);
hcf = gcd(x, y);
lcm = (x*y)/hcf;
printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);
return 0;
}
long gcd(long x, long y) {
if (x == 0) {
return y;
}
while (y != 0) {
if (x > y) {
x = x - y;
}
else {
y = y - x;
}
}
return x;
}
Asp dot net Tutorial Part -10 Out now
https://youtu.be/Zlu8aKaOPgA
https://youtu.be/Zlu8aKaOPgA
YouTube
#10 ASP.NET Course 2022 | Page renders into HTML, coding Technique & server controls | coderbaba
#coderbaba
developed ASPdotnet website working with web page & server control .
topics:
ASP.NET Renders HTML
Response.write()
Coding Techniques in ASP.NET
Developing Web Pages using Visual Studio
Adding a Web Form in our project
Working with…
developed ASPdotnet website working with web page & server control .
topics:
ASP.NET Renders HTML
Response.write()
Coding Techniques in ASP.NET
Developing Web Pages using Visual Studio
Adding a Web Form in our project
Working with…
Const char *p , char const *p What is the difference between the above two?
1) const char *p - Pointer to a Constant char ('p' isn't modifiable but the pointer is)
2) char const *p - Also pointer to a constant Char
However if you had something like:
char * const p - This declares 'p' to be a constant pointer to an char. (Char p is modifiable but the pointer isn't)
TCS TECHNICAL INTERVIEW QUESTIONS:
Write a program to find factorial of a number using recursive function.
• Describe 2 different ways to concatenate two strings.
• Give syntax for SQL and ORACLE joins.
• How is modularity introduced in C++?
• What is the difference between a Stack and a Queue.
• Give example to differentiate between call by value and call by reference.
• Why the usage of pointers in C++ is not recommended ?
• What do you mean by Data mining?
• Write a program to reverse a string.
• Describe these concepts: Polymorphism, Inheritance and Abstraction.
• What is full form of SMAC? Discuss few about it.
• What is cloud computing? Give some of its applications in real world.
• What are stacks? Give some of its applications.
• One rectangular plate with length 8inches,breadth 11 inches and 2 inches thickness is there. what is the length of the circular rod with diameter 8 inches and equal to volume of rectangular plate?
• How would you connect 8 dots with 3 lines.
• Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.
• Can you declare a private method as static?
• How many JVMs can run on a single machine and what is the meaning of Just-In-Time (JIT) compiler?
• Differentiate between copy and default constructor.
• What is #ifdef ? What is its application?
• You are given a singly linked list. How would you find out if it contains a loop or not without using temporary space?
• A person was fined for exceeding the speed limit by 10 mph. Another person was also fined for exceeding the same speed limit by twice the same. If the second person was travelling at a speed of 45 mph. find the speed limit .
• What are different errors encountered while complying?
• How would you implement two stacks using a single array?
• Difference between keyword and identifier.
• What is the Big-O Notation?
• What do you understand by garbage collection in Java? Can it be forced to run?
• What happens if an array goes out-of-bounds?
• What is the role of C++ shorthand’s?
• Discuss the function of conditional operator, size of operator and comma operator with examples.
• Describe friend function & its advantages.
• Differentiate between null and void pointers.
• Write a program to add three numbers in C++ utilizing classes.
• Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
• Explain debugger.
• What are the different types of sorting? Explain the difference between them.
• What is meant by entry controlled loop? What all C++ loops are exit controlled?
Follow @coder_baba
1) const char *p - Pointer to a Constant char ('p' isn't modifiable but the pointer is)
2) char const *p - Also pointer to a constant Char
However if you had something like:
char * const p - This declares 'p' to be a constant pointer to an char. (Char p is modifiable but the pointer isn't)
TCS TECHNICAL INTERVIEW QUESTIONS:
Write a program to find factorial of a number using recursive function.
• Describe 2 different ways to concatenate two strings.
• Give syntax for SQL and ORACLE joins.
• How is modularity introduced in C++?
• What is the difference between a Stack and a Queue.
• Give example to differentiate between call by value and call by reference.
• Why the usage of pointers in C++ is not recommended ?
• What do you mean by Data mining?
• Write a program to reverse a string.
• Describe these concepts: Polymorphism, Inheritance and Abstraction.
• What is full form of SMAC? Discuss few about it.
• What is cloud computing? Give some of its applications in real world.
• What are stacks? Give some of its applications.
• One rectangular plate with length 8inches,breadth 11 inches and 2 inches thickness is there. what is the length of the circular rod with diameter 8 inches and equal to volume of rectangular plate?
• How would you connect 8 dots with 3 lines.
• Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.
• Can you declare a private method as static?
• How many JVMs can run on a single machine and what is the meaning of Just-In-Time (JIT) compiler?
• Differentiate between copy and default constructor.
• What is #ifdef ? What is its application?
• You are given a singly linked list. How would you find out if it contains a loop or not without using temporary space?
• A person was fined for exceeding the speed limit by 10 mph. Another person was also fined for exceeding the same speed limit by twice the same. If the second person was travelling at a speed of 45 mph. find the speed limit .
• What are different errors encountered while complying?
• How would you implement two stacks using a single array?
• Difference between keyword and identifier.
• What is the Big-O Notation?
• What do you understand by garbage collection in Java? Can it be forced to run?
• What happens if an array goes out-of-bounds?
• What is the role of C++ shorthand’s?
• Discuss the function of conditional operator, size of operator and comma operator with examples.
• Describe friend function & its advantages.
• Differentiate between null and void pointers.
• Write a program to add three numbers in C++ utilizing classes.
• Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
• Explain debugger.
• What are the different types of sorting? Explain the difference between them.
• What is meant by entry controlled loop? What all C++ loops are exit controlled?
Follow @coder_baba