LED PANEL

Google It, You'll Get It.

Monday, January 31, 2011

Scan and delete a desired a word from a sentence



#include

main()
{
int i=0;
int length = 0;
int word = 1;
int remove=0;
int tempw=1;

//read the string
char strng[50];
printf("enter the string : ");
gets(strng);
printf("Saved String : ");
puts(strng);
//printf("Initial values : Length %d, word %d, wotd numb %d, i %d. \n",length, word, wn, i);

//calculate the length
while(strng[i]!='\0')
{
length++;
i++;
}
printf("String Length : %d \n",length);

// calculate the no of words
i=0;
word=1;
while(i {
if(strng[i]==' ')
word++;
i++;
}
printf("nO. of Words : %d \n",word);

//askng for the word to delete
printf("Enter the word number you need to delete : ",word);
scanf("%d",&remove);

//scaning for that word
for(i=0;i { if(strng[i]==' ')
tempw++; // 2nd word count
if(tempw==remove)
printf("%c",strng[i]);
}
}

Scan a Character win a string and replace it if its available

#include<'stdio.h'>

main()
{
char name[20];
//input
printf("enter the name : ");
scanf("%s",&name);

//out
printf("**%s** \n",name);

//count
int count=1;
for(count=0;name[count]!='\0';count++);
printf("count %d \n",count);

flushall();

/*
char n;
printf("enter the letter : ");
scanf("%c",&n);

int ncount = 0, i =0;
for(i=0;i<=count;i++)
if(name[i]==n)
ncount++;

printf("ncount %d \n",ncount);*/


//scanng lettr
char n;
printf("enter the letter (scan) : ");
scanf("%c",&n);
flushall();

//replacing letter
char m;
printf("enter the letter (replace): ");
scanf("%c",&m);

int i =0;
for(i=0;i<=count;i++)
if(name[i]==n)
name[i]=m;

printf("%s",name);




}

Palindrome Word checker

What are palindrome Words? http://rinkworks.com/words/palindromes.shtml



#include
main()
{
char word[10], test='T';
int l = 0, i = 0; // l=length

printf("enetr the word : ");
scanf("%s",&word);

//length checkng
for (i=0;word[i]!='\0';i++)
{
l++; // length of the word
}
printf("wrd count %d \n",l);

//check
/* while(i!=l)
{
while( word[i]==word[l-i] )
{
printf("match");
i++;
//j--;
}

}
*/
//checkz
l=i-1;
for(i=0;i<(l/2);i++)
{
if(word[i]!=word[l-i])
test='F';
}

if(test=='T')
printf("Yes");
else
printf("No");
}

String Counter in Simple C

#include<'stdio.h'>
main()
{
char fname[10];
char lname[10];

int fc=0,lc=0,i=0;

printf("----in----\n");
scanf("%s",&fname);
scanf("%s",&lname);

printf("----out----\n");
printf("%s \n",fname);
printf("%s \n",lname);


i=0;
while(fname[i] != '\0')
{
fc++;
i++;
}

i=0;
while(lname[i] != '\0')
{
lc++;
i++;
}



printf("\nfrst : %d \n",fc);
printf("lst : %d \n",lc);
}

Using %s for strings + char array

#include<'stdio.h'>
main()
{
char fname[10];
char lname[10];

printf("----in----\n");
scanf("%s",&fname);
scanf("%s",&lname);

printf("----out----\n");
printf("%s \n",fname);
printf("%s \n",lname);
}

Larges and the smallest number in a series

#include
main()
{

int in[5], temp=0 ,i=0,j;

//----input
printf("Enter 5 digits \n\n");
for(i=0;i<5;i++)
{
scanf("%d",&in[i]);
}

//-----sort
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(in[i]>in[j])
{
temp=in[i];
in[i] = in[j];
in[j] = temp;

}
}
}

//-----output
/*printf("\nafter sorting \n\n");
for(i=0;i<5;i++)
{
printf("%d \n",in[i]);
} */



//Print the samllest
printf("the smallest number : %d \n",in[0]);


//Print the largest
printf("the largest number : %d \n",in[4]);
}

Sorting

#include<'stdio.h'>
main()
{

int in[5], temp=0 ,i=0,j;

//----input
printf("Enter 5 digits \n\n");
for(i=0;i<5;i++)
{
scanf("%d",&in[i]);
}

//-----sort
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(in[i]>in[j])
{
temp=in[i];
in[i] = in[j];
in[j] = temp;

}
}
}

//-----output
printf("\nafter sorting \n\n");
for(i=0;i<5;i++)
{
printf("%d \n",in[i]);
}
}

using nested for loops to built a numeric triangle

o:
1
22
333
4444
----------------------

#include<'stdio.h'>
main()
{

for(int loop=1; loop<=4;loop++)
{
for(int j=0; j {
printf("%d",loop);
}
printf("\n");
}

}

Using If and Else with decimal points in printf

#include<'stdio.h'>
main()
{

float sal,tot, inc;

printf("enter your salary : ");
scanf("%f",&sal);

if( sal < 10000 )
{inc=sal*1.345/100;
tot=(sal*101.345)/100; }
else if( sal < 25000 )
{inc=sal*0.75/100;
tot=(sal*100.75)/100; }
else if( sal >=25000 )
{inc=sal*0.456/100;
tot=(sal*100.456)/100; }
printf("\n\n");
printf("Basic Sal : %.2f \n",sal);
printf("Increment : %.3f \n",inc);
printf("Total : %.2f \n",tot);

}

Counts Odds and Even Digits in a 5 Digit Number

#include<'stdio.h'>
main()
{
long numb, rem, i, temp = 0, sum, in, count = 0, even=0, odd=0;
printf("Input a 5 digit number \n");
scanf("%ld",&numb);
i = 1;

//printf("Input a digit \n");
//scanf("%ld",&in);

printf("\n");
while(i<=5)
{
temp=temp*10;
rem=numb%10;
//checking
if(rem%2>0)
odd++;
else
even++;

//if(rem==in)
//count++; //c= rem, numb =a
temp=temp+rem;
sum=sum+rem;
i++;
rem=0;
numb=numb/10;

}


//printf("%ld appears in here for %ld time \n",in,count);
printf("Total No. of Odd numberz : %ld \n",odd);
printf("Total No. of Even numberz : %ld \n",even);



// printf("inverse is %ld",temp);

}

Calculator using if and while to run till you need

#include<'stdio.h'>
#include<'conio.h'>

main()
{
int a, b, sum;
char choice = 'y';
char select;
while(choice == 'y')
{
printf("Enter the two values : \n");
scanf("%d %d",&a,&b );
flushall();

printf("/n/n MENU ");
printf(" a. Addition ");
printf(" b. Subtraction ");
printf(" c. Multiplication ");
printf(" d. Division ");
printf(" e. Exit /n/n");

printf("/n Select from above : ");
scanf("%c",&select);
flushall();

while(select != 'e')
{
if(select=='a')
sum = a + b;
if(select=='b')
sum = a - b;
if(select=='c')
sum = a * b;
if(select=='d')
sum = a / b;

printf("/n %d",sum);
sum = 0;
}

}
printf("Continue : ( Y or N )");
scanf("%c",&choice);

}

Inverse and the sum of digits in 5 digit number

I: 52013
O: Invrse : 31025
O: Sum : 11
-------------------------------


#include<'stdio.h'>
main()
{
long numb, rem, i, sum=0;
printf("Input a 5 digit number : ");
scanf("%ld",&numb);
i = 1;

printf("inverse is ");
while(i<=5)
{
rem=numb%10;
numb=numb/10;
printf("%ld",rem);
i++;
sum = sum + rem;
rem=0;


}

printf("\n sum is %ld",sum);
}

Scan and count the times you have used a number within a 5 digit Number + creates the inverse of the input

Input: 59585
Input: Scan for Number 5
Output: 5 have printed 3 times
Output: inverse 58595

----------------------------------------------------------

#include<'stdio.h'>

main()
{
long numb, rem, i, temp = 0, sum, in, count = 0;
printf("Input a 5 digit number \n");
scanf("%ld",&numb);
i = 1;

printf("Input a digit \n");
scanf("%ld",&in);

printf("\n");
while(i<=5)
{
temp=temp*10;
rem=numb%10;
if(rem==in)
count++; //c= rem, numb =a
temp=temp+rem;
sum=sum+rem;
i++;
rem=0;
numb=numb/10;

}


printf("%ld appears in here for %ld time \n",in,count);

printf("inverse is %ld",temp);

}

Taking the Inverse of an Input

Input : 85974
Output : 47958


#include<"stdio.h">
main()
{
int numb, rem, i;
printf("Input a 5 digit number \n");
scanf("%d",&numb);
i = 1;

while(i<=5)
{
rem=numb%10;
numb=numb/10;
printf("%d",rem);
i++;
rem=0;

}


}

Inter-changing the values of two variables

#include

main()
{
int x, y, z;

printf("enter the first value \n");
scanf("%d",&x);
printf("enter the second value \n");
scanf("%d",&y);

z = x;
x = y;
y = z;

printf("\nx = %d", x);
printf("\ny = %d", y);
}

Using a WHILE to continusly run a programme until u wish to terminate

#include

main()
{
int x, y, sum, c=1 ;

while(c==1) // c = choice
{
printf("enter the first value \n");
scanf("%d",&x);
printf("enter the second \n");
scanf("%d",&y);

sum = x + y;

printf("the sum is %d", sum);

printf("retry?? if YES press 1, if NO press 0 \n");
scanf("%d",&c);

}

}

Simple Calculator with Four Operators

#include<"stdio.h">

main()
{
int x, y;
float sum1, sum2, sum3, sum4;

printf("enter the first value \n");
scanf("%d",&x);
printf("enter the second \n");
scanf("%d",&y);

sum1 = x + y;
sum2 = x - y;
sum3 = x * y;
sum4 = x / y;

printf("the x + y is %f", sum1);
printf("\nthe x - y is %f", sum2);
printf("\nthe x * y is %f", sum3);
printf("\nthe x / y is %f", sum4);

}

Testing For a Prime Input(Number)

#include

main()
{
int i=1;
int num;
int choice = 1;

while(choice ==1)
{
printf("please enter the value to identify\n");
scanf("%d",&num);
printf("\n");

while(i<=num)

{
int count=0;
int a=1;

while(a<=i)
{
if(i%a==0)
{ count++; }
a++;
}

if(count==2 && num == i)
{
printf("%d", i);
printf(" a prime number \n\n");
}
i++;


}
printf("----------------------------------------\n"); //
printf("retry?? if YES press 1, if NO press 0\n"); //
scanf("%d",&choice); //
printf("----------------------------------------\n"); //
i=1;
}
// return 0;
}

Finiding a Prime Number or Not

#include<"stdio.h">

main()

{

int input, loop =2, rem, flag = 0;
printf("enter a number : ");
scanf("%d",&input);

if(input==1)
{printf("not a prime");}
else
{
while(loop{
rem=input%loop;
if(rem==0)
{
printf("Not a Prime");
loop=input;
flag =1 ;
}
loop++; // loop = loop + 1
}
if(flag==0)
{printf(Yes its prime number");}
}
}

Multiple Reading and Writing

#include"< stdio.h >"

main()
{
int x,y,z;

// Declaring three Integer variables where u can store numbers within range

printf("Enter Three Numbers : (Press Enter after each number)\n");
scanf("%d %d %d",&x,&y,&z);

// %d says the input is an integer. (it have used three times since three inputs)
// &x point gives the address of variable x to store the value on x
// &y point gives the address of variable x to store the value on y
// &z point gives the address of variable x to store the value on z

printf("the values you entered is : %d %d %d ",x,y,z);

// %d says the input is an integer (it have used three times since three outputs)
// x gives the value which have stored in it
// y gives the value which have stored in it
// z gives the value which have stored in it

}

Read and Write

#include"< stdio.h >"

main()
{
int x; // Declaring an Integer variable where u can store numbers within range

printf("Enter A Number : ");
scanf("%d",&x);
// %d says the input is an integer.
// &x point gives the address of variable x to store the value of x

printf("the value you entered is : %d ",x);
// %d says the input is an integer
// x gives the value which have stored in it

}

Fundamental - "Welcome to C"

#include"< stdio.h >"

main()
{
printf("Welcome to C Programming \n"); // displays output
printf("Bye Bye\n");
}



========================================
When You Consider about the above coding, it is the simplest coding you can write using C.

#include"< stdio.h >" :
the header file which have used to complete this coding. basically it is a very common header file which we have to use.

"stdio" : stands for STandarD Input Output
".h" : indicates that it is a header file in the library

so the stdio.h means standard input output header file.

it uses to read a input from a user and to display or print anything for the user.

main():
display or commands the compiler saying that it is the main programme of the coding.
since its a small coding you wont feel the advantage and purpose of writing it. but when u learn the 'functions', im sure u'll undrstand it very well.

{}:
curly braces are neccesary or in other words its a must in a coding to seperate each parts, and also to seperate functions(or for now just think it like processes).

printf:
it have used to display a the message which is in between the Parentheses
[ Ex: (xxx_message_xxx) ].
It is a pre defined functioned which is actuly defined in the header file called stdio.h. to use that function only we need to use this header file. So since the display or the output is necessary in a programe we use this header file most of the time.

"\n" :
command to use the next line.

//comment(or a message about the code) :
that how u make a comment, and i'm gonna use it in further codings also.... all the things which you are typing after two forward slashes wont get compile from the compiler. it consider all those after // as comments.