simple c logic

 simple c  lan some program logics

C simple logic code for preparation :

//reverse of number

#include

void main()

{

int n = 123, rev = 0;

while (n > 0) {

rev = rev * 10 + n % 10;

n = n / 10;

printf("%d", rev);

}

//palindrome

int n = 121, temp = n, rev = 0;

while (n > 0) {

rev = rev * 10 + n % 10;

n /= 10;

}

if (rev == temp)

printf("Palindrome");

else

printf("Not Palindrome");

//table

int n = 5;

for (int i = 1; i <= 10; i++)

printf("%d x %d = %d\n", n, i, n*i);

//summ of n numbers

int n = 10

int sum = n * (n + 1) / 2

printf("%d", sum)

//count digits

int n = 4567, count = 0;

while (n > 0) {

count++;

n /= 10;

}

printf("%d", count);

//sum of even

int sum = 0;

for (int i = 1; i <= 100; i++) {

if (i % 2 == 0)

sum += i;

}

printf("%d", sum);

//sum of array

int a[] = {1, 2, 3, 4, 5}, sum = 0;

for (int i = 0; i < 5; i++)

sum += a[i];

//largest element in array

int a[] = {5, 8, 2, 9, 1};

int max = a[0];

for (int i = 1; i < 5; i++) {

if (a[i] > max)

max = a[i];

}

//smallest element in array

int a[] = {7, 3, 9, 1, 6};

int min = a[0];

for (int i = 1; i < 5; i++) {

if (a[i] < min)

min = a[i];

}

//reverse of an array

int a[] = {1, 2, 3, 4};

for (int i = 3; i >= 0; i--)

printf("%d ", a[i]);

//count vowels in a string

char s[] = "hello";

int count = 0;

for (int i = 0; s[i] != '\0'; i++) {

if (s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')

count++;

}

printf(“%d”,count);

//check character is alpha or not

char ch = 'A';

if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))

printf("Alphabet");

else

printf("Not Alphabet");

Naga Teja.......

linkedin:

hackerrank:

Comments

frequently used resource

C LANGUAGE

Operators and expressions

Looping statements in c