Skip to content

Instantly share code, notes, and snippets.

@LokeshKumarES
LokeshKumarES / reverse_file_words.py
Last active December 13, 2022 04:13
Write a Python program to reverse each word in file.
# text1.txt content
'''
hello easter science
how are you
we assist you to choose the best
'''
with open('test1.txt', 'r') as r_file:
x = r_file.readlines()
res = []
@LokeshKumarES
LokeshKumarES / Encryption_Algorithm.py
Created December 3, 2022 14:16
You are invited to participate in an encryption algorithm competition. Encryption is a method to change the formation of the message using pre-defined rules. After encryption, the message becomes secure and illegible. Develop a program that takes user input as a string sentence and prints its encryption version using the following rules:
'''
You are invited to participate in an encryption algorithm competition. Encryption is a method to change the formation of the message using pre-defined rules. After encryption, the message becomes secure and illegible.
Develop a program that takes user input as a string sentence and prints its encryption version using the following rules:
1. You must include your ID, name and section number as sample input.
2. The program should also include your ID as a prefix to all input sentences.
3. Each word should be encrypted separately.
4. If a word starts with consonant letter, then that word should be shifted two places in circular way. For example, “trend” become “ndtre”, “brown” become “wnbro”, etc.
5. Also, aftershifting, do append “ay” at the end of the word. So, a word “trend” become “ndtreay”.
6. If a word starts with a vowel letter, then it should be encrypted by simply appending "way". For example, “end” becomes “endway”.
7. The letter 'y' is a treated as a consonant if it appears as the
@LokeshKumarES
LokeshKumarES / L9Q1_first_array_program.c
Last active March 12, 2022 15:01
C Array, What are Arrays in C. Properties, Advantages, Disadvantages, Declaration and Initialization of Arrays.
#include<stdio.h>
int main(){
int i=0;
//method 1: declaration of array
//int marks[5];
//method 2: declaration with initialization of array
int marks[5] = {80, 60, 70, 85, 75};
@LokeshKumarES
LokeshKumarES / L8Q5_pragma_Miscellaneous_Directives.c
Created December 26, 2021 12:46
#pragma Miscellaneous Directives, for assigning order to functions.
# include<stdio.h>
void abc();
void xyz();
# pragma startup abc
# pragma exit xyz
void main()
{
printf("\n Main Function.");
}
@LokeshKumarES
LokeshKumarES / L8Q5_undef_Miscellaneous_Directives.c
Last active December 26, 2021 12:47
#undef Miscellaneous Directives, to undefined macro name.
# include<stdio.h>
# define BOY
# undef BOY
void main(){
#ifdef BOY
printf("This is a boy.");
#endif // BOY
@LokeshKumarES
LokeshKumarES / L8Q4_if_else_directives.c
Created December 19, 2021 12:46
Conditional Compilation: (#if and #else directives). The block of code will be processed based on expression result.
#include<stdio.h>
# define TEST 5
int main(){
# if TEST < 5
printf("TEST is smaller than 5.");
# elif TEST == 5
printf("TEST is equal to 5.");
# else
printf("TEST is greater than 5.");
@LokeshKumarES
LokeshKumarES / L8Q3_Conditional_Compilation.c
Last active December 19, 2021 12:40
What is Conditional Compilation? how to use #ifdef #else #endif block by macro name
#include<stdio.h>
# define BOY
int main()
{
//Conditional Compilation
# ifdef BOY
printf("He is a boy.");
# else
printf("She is a girl.");
@LokeshKumarES
LokeshKumarES / L8Q2_File_Inclusion_C_Preprocessor.c
Created July 10, 2021 13:48
We have two cases where we use file inclusion: a. If programer is dealing with a very large program. b. If similar functions and macro definitions are using frequently.
#include<stdio.h>
#include "circle.c"
#include "circle.h"
int main()
{
float r = 4.0;
printf("%.2f", circle_area(r, PI));
return 0;
}
@LokeshKumarES
LokeshKumarES / L7Q6_Static_Storage_Class_Compilation_Time.c
Created November 5, 2020 13:49
Lets compare the compilation time for all the four storage classes of variable in c.
//Static Storage Class Variable
//Speed Test
#include<stdio.h>
#include<time.h>
int main()
{
static int i;
for(i=1;i<=100000000;i++);
@LokeshKumarES
LokeshKumarES / L7Q6_External_Storage_Class_Compilation_Time.c
Created November 5, 2020 13:49
Lets compare the compilation time for all the four storage classes of variable in c.
//External Storage Class Variable
//Speed Test
#include<stdio.h>
#include<time.h>
int i;
int main()
{
for(i=1;i<=100000000;i++);
int ticks=clock();