C Code 40 _ To Write a C Program to Reverse each word in a given sentence

C Code 40 _ To Write a C Program to Reverse each word in a given sentence


Sample Input: 


abcd  efg  hij

Sample Output:


dcba  gfe  jih


Program:


#include<stdio.h>
#include<string.h>
int main()
{
char input[20];
int size,i,initial=0,j;
printf("\nEnter a Sentence : ");
gets(input);
size=strlen(input);
printf("\n\nSentence with reversed words : ");
for(i=0;i<=size;i++)

if(input[i]==' '||input[i]=='\0')
{
for(j=i-1;j>=initial;j--)
{
  printf("%c",input[j]);
}
printf(" ");
initial=i+1;
    }
}
return 0;
}



Output:










Thank You ...


* * * * * * * *  The above Program is contributed by AjayRam KV  * * * * * * * * *

C Code 39 _ To Find the sum of elements in each row of the given matrix

C Code 39 _ To Find the sum of elements in each row of the given matrix 

If a matrix is a 2x2 matrix then there are two rows .
so find the sum of elements in the two rows and display it.

Sample Input:

1 2 3
4 5 6

Sample Output:

sum of elements of row 1 is 6           //i.e. 1 + 2 + 3
sum of elements of row 2 is 15         //i.e. 4 + 5 + 6

Program:


#include<stdio.h>
int main()
{
int a[50][50];
int s[50];
int i,j,m,n,sum,k=0;
printf("\nEnter no of rows : ");
scanf("%d",&i);
printf("\nEnter no of columns : ");
scanf("%d",&j);
printf("\nEnter %d elements :  \n",i*j);
for(m=0;m<i;m++)
{
for(n=0;n<j;n++)
{
scanf("%d",&a[m][n]);
}
}
for(m=0;m<i;m++)
{
sum=0;
for(n=0;n<j;n++)
{
sum=sum+a[m][n];
}
s[k]=sum;
k=k+1;
}
printf("\n");
for(i=0;i<k;i++)
{
printf("\nSum of row %d is :  %d",i+1,s[i]);
}
return 0;
}


Output:











Thank You ...

C Code 38 _ To Find whether the given string has the characters arranged in alphabetical sequence order or not

C Code 38 _ To Find whether the given string has the characters arranged in alphabetical sequence order or not


Sample Input 1:

cdeg

Sample Output 1:

Characters are NOT in Sequence


Sample Input 2:

uvwxyz

Sample Output 2:

Characters are in sequence


Program:


#include<stdio.h>
int main()
{
int n,i,a,b,d=0;
char c[30];
printf("Enter a string of characters : ");
gets(c);
n=strlen(c);
for(i=0;i<n-1;i++)
{
a=c[i];
b=c[i+1];
if((a)!=(b-1))
{
d=1;
break;
}
}
if(d==0)
{
printf("\n\nThe Given Characters are in Sequence");
}
else
{
printf("\n\nThe Given characters are NOT in Sequence");
}
return 0;
}


Output:













Thank You ...


C Code 37 _ To Find the First , Last and Middle Elements in the given array

C Code 37 _ To Find the First , Last and Middle Elements in the given array


Sample Input :

No of element : 3

Elements : 3  6  9

Sample Output:

First Element => 3

Middle Element => 6

Last Element => 9


Note : 

If there are even number of elements in the array we can not find the middle element so in such case print the middle element value as NOT FOUND .


Program:


#include<stdio.h>
int main()
{
int n,i;
int a[100];
printf("Enter no of elements in array : ");
scanf("%d",&n);
if(n>0)
{
printf("\n\nEnter %d elements : ",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n\nFirst Element => %d",a[0]);
if(n%2==1)
{
printf("\n\nMiddle Element => %d",a[n/2]);
}
else
{
printf("\n\nMiddle Element => NOT FOUND");
}
printf("\n\nLast Element => %d",a[n-1]);
}
else
{
printf("\n\nEnter only positive values");
}
return 0;
}


Output:








Thank You ...



C Code 36 _ To Remove the repeating characters from the given string


C Code 36 _ To Remove the repeating characters from the given string 


Sample Input:

Hello

Sample Output:

Helo


Program:


#include<stdio.h>
#include<string.h>
int present(char c,int m);
char str[200],ans[200];

int present(char c,int m)
{
                int v=0;
                int k;
                for(k=0;k<m;k++)
                {
                                if(c==ans[k])
                                {
                                                v=1;
                                                break;
                                }
                }
                if(v==1)
                {
                                return 1;
                }
                else
                {
                                return 0;
                }
}


int main()
{
                int i,len,j=0,p,k;
                printf("\nEnter a String : ");
                scanf("%s",str);
                len=strlen(str);
                printf("Length of original string : %d",len);
                for(i=0;i<len;i++)
                {
                                p=present(str[i],j);
                                if(!p)
                                {
                                                ans[j]=str[i];
                                                j=j+1;
                                }
                }
                printf("\n\nFinal String : %s",ans);
                printf("\nLength of Final String : %d",strlen(ans));
                return 0;
}


Output: 









Thank You ...



C Code 35 _ To Perform Encryption and Decryption using Caesar Cipher


C Code 35 _ To Perform Encryption and Decryption using Caesar Cipher 


Sample Input:


Message to Encrypt  :  abcd

Shifting value : 2

Sample Output:


Encrypted Message  :  cdef

Explanation:


According to the shift value right we need to shift each character.

if we shift ' a ' two times right we get ' c ' , simillarly if we shift ' y ' two times right we get ' a ' and so on.

Simillarly for decryption we need to shift  value left .

if we shift ' d ' one time left we get ' c ' and if we shift ' a ' one time left we get ' z ' and so on.


Program:


#include<stdio.h>
int main()
{
                char str[200],stre[200];
                int n,i=0,m,ch;
                printf("* * * Encryption and Decryption of a Message using Caesar Cipher * * *");
                printf("\n\n1 - Encryption\n2 - Decryption\n\nEnter Your Choice : ");
                scanf("%d",&ch);
                switch(ch)
                {
                                case 1:
                                                printf("\n\nEnter a String to encrypt : ");
                                                fflush(stdin);
                                                gets(str);
                                                printf("\n\nEnter a shift value(number) : ");
                                                scanf("%d",&n);
                                                while(str[i]!='\0')
                                                {
                                                                if(str[i]==32)
                                                                {
                                                                                stre[i]=str[i];
                                                                                i=i+1;
                                                                }
                                                                else
                                                                {
                                                                                if(str[i]>=65&&str[i]<=90)
                                                                                {
                                                                                                m=(int)str[i]-65;
                                                                                                m=(m+n)%26;
                                                                                                stre[i]=m+65;
                                                                                }
                                                                                else if(str[i]>=97&&str[i]<=122)
                                                                                {
                                                                                                m=(int)str[i]-97;
                                                                                                m=(m+n)%26;
                                                                                                stre[i]=m+97;
                                                                                }
                                                                                else
                                                                                {
                                                                                                stre[i]=str[i];
                                                                                }
                                                                                i=i+1;
                                                                }
                                                }
                                                stre[i]='\0';
                                                printf("\n\nEncrypted string : %s",stre);
                                                break;
                               
                                case 2:
                                                printf("\n\nEnter a String to decrypt : ");
                                                fflush(stdin);
                                                gets(stre);
                                                printf("\n\nEnter a shift value(number) : ");
                                                scanf("%d",&n);
                                                while(stre[i]!='\0')
                                                {
                                                                if(stre[i]==32)
                                                                {
                                                                                str[i]=stre[i];
                                                                                i=i+1;
                                                                }
                                                                else
                                                                {
                                                                                if(stre[i]>=65&&stre[i]<=90)
                                                                                {
                                                                                                m=(int)stre[i]-65;
                                                                                                m=(m-n)%26;
                                                                                                if(m<0)
                                                                                                {
                                                                                                                m=m+26;
                                                                                                }
                                                                                                str[i]=m+65;
                                                                                }
                                                                                else if(stre[i]>=97&&stre[i]<=122)
                                                                                {
                                                                                                m=(int)stre[i]-97;
                                                                                                m=(m-n)%26;
                                                                                                if(m<0)
                                                                                                {
                                                                                                                m=m+26;
                                                                                                }
                                                                                                str[i]=m+97;
                                                                                }
                                                                                else
                                                                                {
                                                                                                str[i]=stre[i];
                                                                                }
                                                                                i=i+1;
                                                                }
                                                }
                                                str[i]='\0';
                                                printf("\n\nDecrypted string : %s",str);
                                                break;
                                               
                                default:
                                                printf("\n\nEnter a valid choice 1 or 2 only");
                }
                return 0;
}



Output:
















Thank You ...





Fibre Optic Cable


Fibre Optic Cable




The Cable that carry most of our data are fibre optic cable that are laid under the ground.They are laid under the ocean also.

Optical Fibre Cables are made up of thousands of fibre strands.
Each strand is in the size of human hair.

Optical Fibres carry information in the form of light.

The concept of Total Internal Refraction is used in optical fibres to transport the information in form of light.



The main reason for using optical fibre cables are
  • As optical fibre cables uses light to transport information they are faster compared to traditional copper cables.
  • There is less chance of Interference of data transporting through optical fibre cable from external sources.
  • As we know electrons carry data in copper cables so they forms electric field outside the wire which can disturb the flow of data but in Optical Fibres there is no such issues.


There are four layers in Fibre optic cables
  • Core
  • Cladding
  • Buffer
  • Jacket




Core: It carries the light signals by the principle of Total internal Reflection.

Cladding: It keeps the light in the core by acting as a protective coating to the core which stops the light signal from escaping outside of the core.

Buffer: They protect the core and cladding from external pressure and tension. They are commonly coloured as black to prevent light signals getting out.

Jacket: They are the outer most layer of the fibre optic cable. Their purpose is to prevent damage to cable from environmental hazards.

  




 The above Image shows the installation of  fibre optic cables under the lands and also under the oceans.

They are maintained by only some companies like AT&T , Google and Verizon.

The below image shows the network of the fibre optic cables through out the world (Internet).


Advantages of Fibre Optic Cables over Copper Cables:

  • Higher BandWidth
  • Faster Speed
  • Reliable and Flexible   etc...

Applications of Fibre Optic Cables:

  • Internet
  • Medical Equipments.
  • Military and Space applications    etc...




Thank You ...


Popular Posts