Saturday, December 11, 2010

To set the Windows-XP as default booter when we use both XP and Ubuntu.

When we install both Ubuntu and XP in our system.It'll herritate us by going into Ubuntu when we reboot the system.
So to overcome from this,we have to set XP as default O.S..To do this,we have to change a small setting in Ubuntu.

Type this command in command line:

sudo gedit /boot/grub/menu.lst

(search where grub folder located).If you don't have gedit(notepad) in Kubuntu.To install the gedit type this command in terminal:

sudo kate /boot/grub/menu.lst

Then press Enter.One text document opens when we press Enter.In that document these lines will be located:

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default 0

When we reboot the system,have to see at which line XP placed along with Ubuntu.Next we have to paste the XP Number in last line(default 0) in document means We should Enter the XP number that we we have seen when the system booting,instead of "0".Later save the the doucument and close it and restart the system.

Naturally Kubuntu and Ubuntu has booting number "6".So we have to Enter "6"instead of "0"in the document last line.i.e.default 6 in last line of document.

Sunday, November 28, 2010

Write a program toAsk student to Enter his roll number ,three subject marks obtained by Roll no.1 and repeat it for3timesAndprint them

#include

#include

int main()

{

int result [3][4];

int i, j;

for (i=0;i<3;i++)

{

j=0;

printf ("\nEnter the Roll number:-");

scanf ("%d", &result [i][j]);

for (j=1;j<4;j++)

{

printf ("\nEnter the marks of subject no.%2d\n", j);

scanf ("%d", &result [i][j]);

}

}

printf ("The stored values are:\n");

for (i=0;i<3;i++)

{

for (j=0;j<4;j++)

{

printf ("%4d", result [i][j]);

}

printf ("\n");

}

getch ();

}

Write a program to print the values in a matrix table

#include

#include

main()

{

int a[10][10],i,j,r,c;

printf("Enter order or matrix:");

scanf("%d%d", &r,&c);

printf("Enter %d values ", r*c);

for(i=0;i
for(j=0;j
scanf("%d", &a[i][j]);

printf("\n Element of array a: ");

for(i=0;i
{

printf("\n");

for(j=0;j
{

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

}

}

getch();

}

Write a program to print the highest score of the given array?

#include

#include

#define NUM_STUDENTS 25

#define NUM_TESTS 10

int get_highest(int a[][NUM_TESTS], int row, int col);

int main()

{

int grades[NUM_STUDENTS][NUM_TESTS] = { {55, 60, 65},

{85, 90, 95} };

int num_students = 2;

int num_tests = 3;

int high_test;



high_test = get_highest( grades, num_students, num_tests);



printf("The highest score is %d.\n", high_test);

getch();

}



int get_highest(int a[][NUM_TESTS], int row, int col)

/* Assumes that there is at least one element */

{

int i, j;

int highest = a[0][0];



for( i = 0; i < row; i++)

for( j = 0; j < col; j++)

if ( a[i][j] > highest)

highest = a[i][j];

return highest;

}

Write a program to find out the largest and smallest values of a Matrix?

#include

#include

main()

{

int a[10][10];

int l,s,i,j,p,q;

printf("Enter the order of matrix: ");

scanf("%d%d", &p,&q);

printf("\n Enter %d values : ",p*q);

for(i=0;i
{

for(j=0;j
scanf("%d", &a[i][j]);

}

l=0;

s=a[0][0];

for(i=0;i
{

for(j=0;j
{

if(l
l=a[i][j];

if(a[i][j]
s=a[i][j];

}

}

printf("\n\n");

printf("Element of matrix a: ");

for(i=0;i
{

printf("\n");

for(j=0;j
{

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

}

}

printf("\n The biggest values: %d", l);

printf("\n The smallest value:%d",s);

getch();

}

Write a program to read data and determine the following ,Total marks obtain by each student,The highest marks in each subject with Rollno, highest st

#include

int main()

{

int result[10][5],i,j,k,total,maxr,maxm;



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

total=0;

for(j=0;j<4;j++)

{

if(j==0)

puts("Enter Roll number\t");

else if(j==1)

puts("Enter 1st subject marks\t");

else if(j==2)

puts("Enter 2nd subject marks\t");

else if(j==3)

puts("Enter 3rd subject marks\t");

scanf("%d",&result[i][j]);

if(j!=0)

total+=result[i][j];

}

result[i][j]=total;

}



puts("Mark sheet");

printf("\n%6s%6s%6s%6s%6s\n","Roll","1st","2nd","3rd","Total");

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

{

for(j=0;j<5;j++)

{

printf("%6d",result[i][j]);

} printf("\n");

}

puts("Press any key....");

getch();

puts("Roll number with total");

printf("\n%6s%6s\n","Roll","Total");

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

{

for(j=0;j<5;j++)

{ if((j==0)||(j==4))

printf("%6d",result[i][j]);

}

printf("\n");

}

for(i=1;i<4;i++)

{

for(j=0;j<5;j++)

{

if(j==0)

{

maxm=result[j][i];

maxr=result[j][0];

}

else if(result[j][i]>maxm)

{

maxm=result[j][i];

maxr=result[j][0];

}

}

if(i==1)

printf("\nMaximum marks in sub1 is %d, Roll number %d",maxm,maxr);

else if(i==2)

printf("\nMaximum marks in sub2 is %d, Roll number %d",maxm,maxr);

else if(i==3)

printf("\nMaximum marks in sub3 is %d, Roll number %d",maxm,maxr);

}

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

{

for(j=0;j<5;j++)

{

if(j==4)

{

if(i==0)

{

maxm=result[i][j];

maxr=result[i][0];

}

else if(result[i][j]>maxm)

{

maxm=result[i][j];

maxr=result[i][0];

}

}

}

}

printf("\nMaximum total is %d and Roll number %d",maxm,maxr);

getch();

}

Write a program that reads in four integers and determines and prints the largest and the smallest integers in the group?

#include

#include



#define MAX_INTS 4



int main()

{

int min = INT_MAX;

int max = INT_MIN;

int a[ MAX_INTS ];

int i;



for (i = 0; i < MAX_INTS; i++)

{

printf( "Enter number %d of %d : ", (i + 1), MAX_INTS);

scanf( "%d", &a[i] );



if ( a[i] < min) min = a[i];

if ( a[i] > max) max = a[i];

}



printf("%d is the smallest number\n", min);

printf("%d is the largest number\n", max);



return 0;

}

Write the program to calculate the Median of a given array

#include

main()

{

int i,j,n;

float median,t;

printf("Enter the size of the array\n");

scanf("%d",&n);

float a[n];

printf("Enter the values\n");

for(i=0;i
scanf("%f",&a[i]);

for(i=0;i
{

for(j=1;j
{

if(a[j-1]
{

t=a[j-1];

a[j-1]=a[j];

a[j]=t;

}

else

continue;

}

}

if(n%2==0)

median=(a[n/2]+a[n/2+1])/2;

else

median=a[n/2+1];

for(i=0;i
printf(" %.2f",a[i]);

printf("\nMedian is =%f\n",median);

getch();

}

write a program to Reverse the digits by using do-while loop

#include
#include
main()
{
int number = 123;
int rightMostNumber = 0;
int temp = 0;

temp = number;

do
{
rightMostNumber = 10*rightMostNumber + temp % 10;
temp = temp/10;
} while (temp);

printf ("\nThe number %d reversed is %d\n", number, rightMostNumber );
getch();
}

write a program to find given number is palidrome or not by using while loop?

#include

#include

main()

{

int n,t,s,r;

printf(“Ent er any number:”);

scanf(“%d”,&n);

t=n;

s=0;

while (n>0)

{

r=n%10;

s=(s*10)+r;

n=n/10;

}

if(t==s)

printf(“%d is a Palindrome number”, t);

else

printf(“%d is not a Palindrome number”, t);

getch();

}

write a program To print armstrong number using while loop

#include

#include

main()

{

int n,t,s,r;

printf(“Ent er any number:”);

scanf(“%d”,&n);

t=n;

s=0;

while (n>0)

{

r=n%10;

s=s+(r*r*r);

n=n/10;

}

if(t==s)

printf(“%d is a Armstrong number”, t);

else

printf(“%d is not a Armstrong number”, t);

getch();

}

write a program to find given number is prime number or not by using while loop

#include

#include

main()

{

int n,i,k;

printf(“Enter any number:”);

scanf(“%d”, &n);

i=1;

k=0;

while(i<=n)

{

if(n%i==0)

k=k+1;

i++;

}

if(k==2)

printf(“%d is a prime number”,n);

else

printf(“%d is not a prime number”,n);

getch();

}

write a programTo print average of odd numbers below user given range

#include

#include

main()

{

int i,r,c,t;

float a;

printf(“Enter the range:”);

scanf(“%d”, &r);

i=1; c=0; t=0;

while(i<=r)

{

if (i%2!=0)

{

t=t+i;

c++;

}

i++;

}

a=t/c;

printf(“\nThe average of odd numbers below &d: %f”,r,a);

getch();

}

write a program to print sum of digits upto given number

#include
#include
int main(void)
{
long sum = 1L;
int j = 1;
int count = 10;
int i;
for(i = 1 ; i <= count ; i++)
{
sum = 1L;
j=1;
printf("\n1");

while(j < i){
sum += ++j;
printf("+%d", j);
}
printf(" = %ld\n", sum);
}
getch();
}

To print floy’s triangle using for loop

#include

#include

main()

{

int i,j,t,row;

printf(“Enter number of rows:”);

scanf(“%d”,&row);

t=1;

for(i=0;i
{

for(j=0;j<=i;j++)

{

if(t<10)

printf(“%d “,t);

else

printf(“%d “,t);

t++;

}

printf(“\n”);

}

getch();

}

write a program To print asterisks graph using for loop

#include

#include

main()

{

int i,j,row;

printf(“Enter number of rows:”);

scanf(“%d”,&row);

for(i=1;i<=row;i++)

{

for(j=1;j<=i;j++)

{

printf(“* “);

}

printf(“\n”);

}

getch();

}

Write a program to check the given character whether it is vowel or consonant?

#include

#include

main()

{

char a;

printf("Enter any small letter(a-z) \n");

scanf("%c",&a);

//a = getchar();

if((a =='a') || (a == 'e') || (a =='i') || (a == 'o') || (a == 'u'))

printf("It is a vowel ");

else

printf("It is a consonant");

getch();

}

Write a program to print the given year is a leap year or not?

#include

main()

{

int year;

printf("Enter a year\n");

scanf("%d",&year);

if(year%4==0 && year%100!=0 ||year%400==0)

printf("Given year is a leap year");

else
printf("Given year is not a leap year");

getch();

}

Write a program to print result of student?

#include

#include

main()

{ int m1,m2,m3,m4,m5,m6,total;

char result, grade,name[15];

float avg;

printf("Enter student name:");

scanf("%s", name);

printf("\n Enter 6 marks:");

scanf("%d%d%d%d%d%d", &m1, &m2, &m3, &m4, &m5, &m6);

total=m1+m2+m3+m4+m5+m6;

avg=total/6;

if(avg>40)

{

result = 'p';

if(avg>75)

grade='d';

else if(avg>60 && avg<=75)

grade='a';

else if(avg>50 && avg<=60)

grade='b';

else

grade='c';

}

else

result='f';

printf("\nstudent name : %s", name);

printf("\nMarks :");

printf("\n%d\t%d\t%d\t%d\t%d\t%d\t",m1,m2,m3,m4,m5,m6);

printf("\nAverage marks : %f",avg);

if(result=='p')

printf("\nResult :pass");

else

printf("\Result :fail");

printf("\Grade :%c",grade);

getch();

}

Write a program to find out biggest number out of three numbers?

#include

#include

main()

{

int a,b,c;

printf("Enter any three numbers:");

scanf("%d%d%d", &a,&b,&c);

if((a>b) && (a>c))

printf ("The big number : %d", a);

else if(b>c)

printf("The big number : %d", b);

else

printf("The big number : %d", c);

getch();

}

Write a program to print concatanation of two names by using pointers

#include

#include

#include



main()

{

char buf[80], *message;



/* Input a string. */

puts("Enter a line of text.");

gets(buf);



/* Allocate the initial block and copy the string to it. */



message = realloc(NULL, strlen(buf)+1);

strcpy(message, buf);



/* Display the message. */



puts(message);



/* Get another string from the user. */



puts("Enter another line of text.");

gets(buf);



/* Increase the allocation, then concatenate the string to it. */



message = realloc(message,(strlen(message) + strlen(buf)+1));

strcat(message, buf);



/* Display the new message. */

puts(message);

getch();

return(0);

}

Write a program ot print Amount of numbers that we have Entered by using pointers.:

#include

#include





int main ()

{

int i,n;

int * pData;

printf ("Amount of numbers to be entered: ");

scanf ("%d",&n);



pData = (int*) calloc (n,sizeof(int));



for (i=0;i
{

printf ("Enter number #%d: ",n);

scanf ("%d",&pData[i]);

}

printf ("You have entered: ");

for (i=0;i
free (pData);

getch();

return 0;

}

Write a program to find GCD of given number by using Recursion..

#include

int recgcd(int x, int y)
{
int r;
if(y==0)
{
return(x);
}
else
{
r=x%y;
return(recgcd(y,r));
}
}
main()
{
int a,b,gcd;
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
gcd=recgcd(a,b);
printf("GCD of %d and %d is = %d\n",a,b,gcd);
}

******************OR***************************************

#include
int gcd(n1,n2)
{
int x;
int limit=n1>n2?n1:n2;
int small=n1
if(limit%small==0) return small;
x=limit%small;
gcd(limit,x);


}
main()
{
int n1,n2;
printf("Enter any two +ve numbers:");
scanf("%d%d",&n1,&n2);

gcd(n1,n2);
printf("%d\n",gcd(n1,n2));
}

Write a C program to find factorial by using recursion

#include
main()
{
int no;
printf("Enter the number:");
scanf("%d",&no);
factorial(no);

printf("Factorial of %d is = %d\n",no,factorial(no));
}
int factorial(int n)
{
if(n<0)
return 0;
if(n==0||n==1)
return 1;
if(n==2)
return (n);
else
return n*factorial(n-1);
}

Write a program to find GCD of given numbers.

#include

int gcd(int m,int n)
{
int g,j;
g=(m>n)?m:n;
j=(m if(g%j==0)return j;
g=g%j;
gcd(g,j);
}

main()
{
printf("\tFinding GCD of given numbers\n");
int m,n;
printf("Enter two numbers : ");
scanf("%d %d",&m,&n);
printf("\tGCD of %d and %d is %d\n",m,n,gcd(m,n));
}

********************OR***********************************

#include

int gcd(int m,int n,int i)
{
static int g=0;
static int j=0;
if(m%i==0 && n%i==0)
j=i;
if(g<=j)
g=j;
if(i==1)return g;
gcd(m,n,i-1);
}

main()
{
printf("\tFinding GCD of given numbers\n");
int m,n,i;
printf("Enter two numbers : ");
scanf("%d %d",&m,&n);
i=(m>n)?n:m;
printf("\tGCD of %d and %d is %d\n",m,n,gcd(m,n,i));
}

Write a C program to Find the nth power of the given number

#include

int power(int n,int i)
{
static int total=1;
if(i==0)return total;
total=total*n;
power(n,i-1);
}

main()
{
printf("Finding the nth power of the given number\n");
int n,i;
printf("Enter your number and power : ");
scanf("%d %d",&n,&i);
printf("%d th power of %d = %d\n",i,n,power(n,i));
}

Write a program to check number is prime or not using recursion.

#include
#include

int prime(int num,int count)
{
if(count{
if(num%count==0)
{
printf("%d is not Prime Number\n",num);
goto exit;
}
count += 1;
if(count {
prime(num,count);
}
}
if(num==count)
{
printf("%d is a Prime Number\n",num);
}
exit:
return 0;
}

int main()
{
int no;
printf("Enter the number = ");
scanf("%d",&no);
prime(no,2);


}

write a C program to print reverse of the given string..

#include

int string_length(char s[])
{
int i;
for (i = 0; s[i]; i++)
;
return i;
}
/* Function reverse */
void string_reverse(char s[])
{
int i, j;
for (i = 0, j = string_length(s)-1; i{
int tmp = s[i];
s[i] = s[j];
s[j] = tmp;

}
}
main()
{
char s[] = "Pavan";
string_reverse(s);
printf("%s\n", s);
}

Reverse a number using recursion in c program..

#include
int reverse(int x)
{
int n,i;
if(n>0)
{
return n;;
}
else if(i==1)
{
i=n%10;
n=n/10;
return i;
}

}

main()
{
int n,i;
printf("Enter the number:");
scanf("%d",&n);
int r=reverse(i);
printf("The Reverse Number is %d\n",r);
}
*****************OR******************************
#include

int Recursion_Reverse(int n)
{
static int rev=0;
if(n==0)return rev;
rev=rev*10+(n%10);
Recursion_Reverse(n/10);
}

main()
{
int a;
printf("Enter your number : ");
scanf("%d",&a);
printf("reverse of %d = %d \n",a,Recursion_Reverse(a));
}

Write a C programm to Reverse Given string and check it palidrome or not..

#include
#include
char string_reverse(char ch[])// function definition
{
int i=0,found=1;
int len=strlen(ch);
for(i=0;i<(len/2+1);i++)
{
if(ch[i] !=ch[--len])// checks chars front with backward chars
{
found=0;
break;
}

}//FOR
if(found==1)
printf("%s is a palindrome\n",ch);
else
printf("%s is Not palindrome\n",ch);
}
main()//Begining of the main function
{
char ch[10];//char array declaration
printf("Enter the string:");
scanf("%s",ch);// takes input from the keyboard

string_reverse(ch);//Function calling
}

Read in an integer n, read in n numbers and find out the mean, median and mode.

#include

#include

static char *ch[20],temp[20];



static int i,j,k,n;

char Display(char *ch[]);//Function Prototype

char SortWords(char *ch[])//Function Definitio

{



printf("\n\n------------------------------------\n\tBefore Sort\n------------------------------------\n\n");

Display(ch);

for(i = 0; i < n;i++)//Loop to compare each with word with

{



for(j = i + 1; j < n;j++)//Loop to compare each ith index word with jth index word

{



if ( strcmp(ch[i],ch[j]) > 0)// if ith index string > jth index

{

strcpy(temp,ch[j]); //swapping

strcpy(ch[j],ch[i]);

strcpy(ch[i],temp);

}

}



}

printf("\n\n------------------------------------\n\tAfter Sort\n------------------------------------\n\n");

Display(ch);





}



char Display(char *ch[])//Display the strings

{

for(i = 0; i < n;i++)

printf("%s ",ch[i]); //printin after sorting

}

//////////////////////////////////////////

main()

{

printf("Enter No of Strings\n");

scanf("%d",&n);//no of string that we enter



for(i=0;i
{

ch[i] = ((char *) malloc( 50 * sizeof(char)));

scanf("%s",ch[i]);

}



SortWords(ch);//Function Calling





}//End of Main

Write a program that inputs n names and outputs them in alphabetical order.

#include
#include

static char *ch[20],temp[20];

static int i,j,k,n;
char Display(char *ch[]);//function Prototype
char sortwords(char *ch[])//fuction definition
{
printf("\n\n-----------------------\n\tBefor sort\n----------------------");
Display(ch);
for(i=0;i {
for(j=i+1;j {
if(strcmp(ch[i],ch[j])>0) // if ith index string>jth index
{
strcpy(temp,ch[j]);//swapping
strcpy(ch[j],ch[i]);
strcpy(ch[i],temp);
}
}
}
printf("\n\n-------------------------\n\tAfter sort\n------------------------");
}
main()
{
int n,i;
char ch;
printf("Enter the NO. of string:");
scanf("%d",&n);//no of string that we enter

for(i=0;i {
ch[i]=((char *) malloc(50*sizeof(char)));
scanf("%s",ch[i]);
}
sortwords(ch);//function calling
}//End of main

Write a program that will print out all the rations of a string typed into it by using function Ex: "space": space paces acesp cespa espac

#include
#include
char rotation_words(char ch[])
{
int i,j,k;
int len=strlen(ch);
for(i=0;i {
for(j=i;j {
printf("%c",ch[j]);
if(j>=len-1)
{
for(k=0;k printf("%c",ch[k]);
}
}
printf("\n");
}
}
main()
{
char ch[100];
printf("Enter the string:");
gets(ch);

rotation_words(ch);
}

program that outputs if a given word is a palindrome or not by using funciton Ex:amma is a palindrome.

#include
#include

char polidrome(char ch[])
{
int i=0,found=1;
int len=strlen(ch);
for(i=0;i<(len/2+1);i++)
{
if(ch[i]!=ch[--len])
{
found=0;
break;
}
}
if(found==1)
printf("%s is a polindrome\n",ch);
else
printf("%s is Not a polindrome\n",ch);
}
main()
{
char ch[100];
printf("Enter the string:");
gets(ch);

polidrome(ch);
}

Write C program to find the median

#include
#define N 10
main()
{
int i,j,n;
float median,a[N],t;

printf("Enter the number of items\n");
scanf("%d", &n);
/* Reading item into array a */
printf("Input %d values\n",n);
for(i=1;i<=n;i++)
scanf("%f",&a[i]);
/*sorting begins*/
for(i=1;i<=n-1;i++)
{/* Trip-i begins */
for(j=1;j<=n-i;j++)
{
if(a[j]<=a[j+1])
{/* Ineterchanging values */
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
else
continue;
}
}/* sorting ends */


/* calculation of median */
if(n%2==0)
median=(a[n/2]+a[n/2+1])/2.0;
else
median=a[n/2+1];
/* Printing */
for(i=1;i<=n;i++)
printf("%f",a[i]);
printf("\n\nMedian is %f\n",median);

Write C program to print MAXIMUM and MINIMUM in given numbers.

#include
main()
{
int i,j,n=10,arr[n],temp;
printf("Enter 10 elements :\n");
for(i=0;i {
scanf("%d",&arr[i]);
}
for(i=0;i {
for(j=0;j {
if(arr[i] <= arr[j])
{
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
printf("\t%d is the Minimum value\n",arr[0]);
printf("\t%d is the Maximum value\n",arr[n-1]);
int sum=0;
for(i=0;i {
sum+=arr[i];
}
float average=sum/n*1.0;
printf("\t%.2f is the Average\n",average);
printf("\t%d is the variation \n",arr[n-1]-arr[0]);
}

Write C program to read 1-100 integers , Even ,Odd and Prime numbers.

#include
main()
{
int pavan[100];
int i;
printf("\n\tEven numbers from 1-100:\n\n");
for(i=0;i<100;i++)
{
pavan[i]=i+1;
if(pavan[i]%2==0)
printf("%d ",pavan[i]);
}
printf("\n");
printf("********************************************************************************\n");
/*************************************************************************************************************************/
printf("\n\t0dd numbers from 1-100 :\n\n");
for(i=0;i<=100;i++)
{
pavan[i]=i+1;
if(pavan[i]%2==1)
printf("%d ",pavan[i]);
}
printf("\n");
printf("********************************************************************************\n");
/*************************************************************************************************************************/

int count=0;
int n=0;
int j;
printf("\n\tPrime numbers from 1-100 :\n\n");
for(i=0;i<100;i++)
{
count=0;
for(j=1;j<=pavan[i];j++)
{
if (pavan[i]%j==0)
{
count++;
}
}
if(count==2)
printf("%d ",pavan[i]);

}
printf("\n");
printf("********************************************************************************\n");
/*************************************************************************************************************************/
}

Test a number is even or odd by using bitwise operators

#include
main()
{
int n;
printf("Enter number:");
scanf("%d",&n);
if(n&1==1) // if last bit in number is 1,'n' is ODD, '0' for EVEN
printf("%d is odd\n",n);
else
printf("%d is even\n",n);

}

Write a Program to Reverse

#include
#include
#include
void reverse(char []);
void itoa(int n, char s[])
{

int i = 0;
do
{
s[i++] = n % 10 + '0';

}while ((n /= 10) > 0);
//s[i] = '\0';
while (i >0)
{

printf("%c",s[--i]);

}

printf("\n");
}/*
void atoi(int n, char s[])
{
int i = 0;
do
{ // generate digits in reverse order
s[i++] = n % 10 + '0'; // get next digit
}while ((n /= 10) > 0); // delete it
s[i] = '\0';
while (i >= 0)
printf("%c",s[i--]);

printf("\n");
}*/
main()
{
char ch[10];
char n;
// scanf("%c",&n);
itoa(getchar(),ch);
}

Revise the main routine of the longest-line program so it will correctly print the length of arbitrary long input lines, and as much as possibleoftext

#include

#define MAXLINE 1000

void copy(char to[], char from[]);

/* print longest input line */
int main(void)
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXLINE]; /* current input line */
char longest[MAXLINE]; /* longest line saved here */

max = 0;

while((len = getlines(line, MAXLINE)) > 0)
{
printf("%d: %s", len, line);

if(len > max)
{
max = len;
copy(longest, line);
}
}

if(max > 0)
{
printf("Longest is %d characters:\n%s", max, longest);
}
printf("\n");
return 0;
}

/* getline: read a line into s, return length */
int getlines(char s[], int lim)
{
int c, i, j;

for(i = 0, j = 0; (c = getchar())!=EOF && c != '\n'; ++i)
{
if(i < lim - 1)
{
s[j++] = c;
}
}
if(c == '\n')
{
if(i <= lim - 1)
{
s[j++] = c;
}
++i;
}
s[j] = '\0';
return i;
}

/* copy: copy 'from' into 'to'; assume 'to' is big enough */
void copy(char to[], char from[])
{
int i;

i = 0;
while((to[i] = from[i]) != '\0')
{
++i;
}
}

Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input a line at a time.

#include

#define MAX_LINE 1024

void discardnewline(char s[])
{
int i;
for(i = 0; s[i] != '\0'; i++)
{
if(s[i] == '\n')
s[i] = '\0';
}
}

int reverse(char s[])
{
char ch;
int i, j;

for(j = 0; s[j] != '\0'; j++)
{
}

--j;

for(i = 0; i < j; i++)
{
ch = s[i];
s[i] = s[j];
s[j] = ch;
--j;
}

return 0;
}

int getlines(char s[], int lim)
{
int c, i;

for(i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
{
s[i] = c;
}

if(c == '\n')
{
s[i++] = c;
}

s[i] = '\0';

return i;

}

int main(void)
{
char line[MAX_LINE];

while(getlines(line, sizeof line) > 0)
{
discardnewline(line);
reverse(line);
printf("%s\n", line);
}
return 0;
}

Write a program to print all input lines that are longer than 80 characters.

#include
#define MINLENGTH 10

int readbuffer (char *buffer)
{
int i = 0;
int c;
while (i < MINLENGTH)
{
c = getchar();
if (c == EOF) return -1;
if (c == '\n') return 0;
buffer[i++] = c;



}
return 1;
}

int copyline(char *buffer)
{
size_t i = 0;
int c;
int status = 1;

for(i = 0; i < MINLENGTH; i++)
{
putchar(buffer[i]);
}
while (status == 1)
{
c = getchar();
if(c == EOF) status = -1;
else if ( c == '\n') status = 0;
else putchar(c);
printf("%d\n",status);
}
putchar('\n');
return status;
}

int main(void)
{
char buffer[MINLENGTH];
int status = 1;
while (status != -1)
{
status = readbuffer(buffer);
if (status == 1)
status = copyline(buffer);
}


}

Write a C program to calculate the following Sum: Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!

#include
#include

main()
{
int counter, f_coun;
float sum = 0,x,power,fact;

printf("Enter the value of x\n");
scanf("%f",&x);

for(counter = 0,power = 0; power <=10;counter++,power = power+2)
{
fact = 1;
//printf("Counter Value = %d\n",counter);
for(f_coun = power; f_coun>=1 ; f_coun--)
fact *= f_coun;
sum += ( pow(-1,counter) * ( (pow(x,power) ) / fact ) ); // Equation of Sum Series
}
printf("%f\n",sum);

}

Write a program to count the number of positive and negative numbers...

#include
main()
{
int a[50];
int count_neg=0;
int count_pos=0,i,n;

printf("Enter the size of the array:");
scanf("%d",&n);
printf("Enter the elements of the array:\n");
for(i=0;i scanf("%d",&a[i]);
for(i=0;i {
if(a[i]<0)
count_neg++;
else
count_pos++;
}
printf("There are %d negative numbers in the array\n",count_neg);
printf("There are %d positive numbers in the array\n",count_pos);
}

Write a program to count the number of letters from A-Z in given input

#include

main() {

int c; /* store input char */
int nletters[26]; /*array of 26 cells */
int i; /* handy variable */

for (i = 0; i < 26; ++i)
nletters[i] = 0;

while ((c = getchar()) != EOF) {
if (c >= 'a' && c <= 'z')
++nletters[c - 'a'];
else if (c >= 'A' && c <= 'Z')
++nletters[c - 'A'];
}

for (i = 0; i < 26; ++i) {
c = 'a' + i;
putchar(c);
printf(" = %d\n", nletters[i]);
}

}

Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.

#include
main()
{
int c;
int space = 0;
while( (c = getchar()) != EOF )
{
if ( c == ' ')
{
if ( space == 0)
{
putchar(c);
space = 1;
}
}
if(c !=' ')
{
putchar(c);
space = 0;
}
}
}

Write a program to copy its input to its output, replacing each backspace by \b, and each backslash by \\.

#include

int main()
{
int c, d;

while ( (c=getchar()) != EOF) {
d = 0;
putchar('d');
//putchar((int)c);
if (c == '\\') {
putchar('\\');
// putchar('\\');
d = 1;
}
if (c == '\t') {
putchar('\t');
// putchar('t');
d = 1;
}
if (c == '\b') {
putchar('\b');
// putchar('b');
d = 1;
}
if (d == 0)
putchar(c);
}
return 0;
}

Write a program that prints its input one word per line.

#include
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* count lines, words, and characters in input */
int main()
{
int c;
int inspace = 0;


while((c = getchar()) != EOF)
{
if(c == ' ' || c == '\t' || c == '\n')
{
if(inspace == 0)
{
inspace = 1;
putchar('\n');

}// End Of Second IF
}// End Of First IF
else
{
putchar(c);
inspace = 0;
}

}// End of WHILE
return 0;
}

Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.

#include
main()
{
int c;
int inspace = 0;
while((c = getchar()) != EOF)
{
if(c == ' ')
{
if(inspace == 0)
{
inspace = 1;
putchar(c);
}// End of Second IF
}// End of First IF

}// End of while
}

Write a program to count blanks, tabs.

#include

main()
{
int c,nc,ns,nl,nt;
nc = ns = nl = nt = 0;
while ((c = getchar()) != EOF)// takes prompts for input till press Ctrl + D
{
++nc; // counts no of characters
if (c == '\n') nl++;// counts no of lines
if (c == ' ') ns++;// counts no of spaces
if (c == '\t') nt++;// counts no of tab spaces
}
printf("\nNo Of Characters = %d\nNo Of Lines = %d\nNo Of Spaces = %d\nNo Of tab Spaces = %d\n",nc,nl,ns,nt);
}

Write a program to count characters of input.

#include

main()
{
int c,nc = 0;

while ((c = getchar()) != EOF)// takes prompts for input till press Ctrl + D
{
++nc; // counts no fo characters
}
printf("\nNo Of Characters Entered = %d\n",nc);
}

Write a program to read and accept 5 single characters from the keyboard

#include
main()
{
int c,i;
i = 1;

while (i <= 5)
{
c = getchar();
if ( c == ' ' || c == '\n' || c == '\t')
++i;
}

}

Print out powers of 5: 1, 5, 25, 125, .. up to 5^N

#include
#include

main()
{

int base, power, i,p;// variable declaration
base = power = i = p = 0;// variable initialization
printf("Please Enter Base and Power ( 2^5)\n");
scanf("%d%d",&base,&power);// scanf function takes input from the keyboard

printf("------------+\n");
for(i = 1;i<=power; i++)
{
p = pow(base,i);
printf("%d^%d = %d\n",base,i,p);
}
printf("------------+\n");
}

************************OR****************************
#include
#define N 10
main()
{
int n;
int val=1;
printf("\t n\t 5^n\n");
printf("\t*****************\n");
for (n=0;n<=N;n++)
{
printf("\t%3d \t %6d\n",n,val);
val=5*val;
}
return 0;
}

Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.

#include
main()
{
int fahr, celsius;
int lower, upper, step;
lower = 300; /* lower limit of temperature scale */
upper = 0; /* upper limit */
step = 20; /* step size */
celsius = lower;
printf("Celsius --> Fahrenheit\n");
while (celsius >= upper)
{
fahr = (9.0/5.0) * celsius + 32.0;

if (celsius == 0) printf("%d\t\t%d\n",1, fahr);
else printf("%d\t\t%d\n",celsius, fahr);
celsius = celsius - step;
}
}

*******************OR******************************************
#include
main()
{
int fahr,celsius;
int lower,upper, step;
lower=0;
upper=300;
step=20;
fahr=upper;
while(fahr>=lower)
{
celsius=5*(fahr-32)/9;
printf("%d\t%d\n",fahr,celsius);
fahr=fahr-step;
}
}

Write a program to convert Fahrenheit to celsius

#include

int main(void)
{
float fahr, celsius;
int lower, upper, step;

lower = 0;
upper = 300;
step = 20;

printf("F C\n\n");
fahr = lower;
while(fahr <= upper)
{
celsius = (5.0 / 9.0) * (fahr - 32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}

Write a program to print the corresponding Celsius to Fahrenheit table.

#include

main()
{
int fahr, celsius;
int lower, upper, step;
lower = 0; /* lower limit of temperature scale */
upper = 300; /* upper limit */
step = 20; /* step size */
celsius = lower;
printf("Celsius --> Fahrenheit\n");
while (celsius <= upper) {
fahr = (9.0/5.0) * celsius + 32.0;
if (celsius == 0) printf("%d\t\t%d\n",1, fahr);
else printf("%d\t\t%d\n",celsius, fahr);
celsius = celsius + step;// here the step size is 20, in each iteration celsius value gets incremented by 20
}
}

***************OR********************************
#include

int main(void)
{
float fahr, celsius;
int lower, upper, step;

lower = 0;
upper = 300;
step = 20;

printf("C F\n\n");
celsius = lower;
while(celsius <= upper)
{
fahr = (9.0/5.0) * celsius + 32.0;
printf("%3.0f %6.1f\n", celsius, fahr);
celsius = celsius + step;
}
return 0;
}

Write a C program to print Reverse of string using Arrays

#include

int string_length(char s[])
{
int i;
for (i = 0; s[i]; i++)
;
return i;
}
/* Function reverse */
void string_reverse(char s[])
{
int i, j;
for (i = 0, j = string_length(s)-1; i{
int tmp = s[i];
s[i] = s[j];
s[j] = tmp;

}
}
main()
{
char s[] = "Pavan";
string_reverse(s);
printf("%s\n", s);
}

Write a C program to print Division of the given two decimal number

#include

main()
{
int div=0;
int n=0;
printf("Enter the value of n\n");
scanf("%d",&n);
while (n>0)
{
div=div/n%10;
n=n/10;
}
printf("division=%d\n",div);
}

Write a C program to print Addition of the given two decimal number

#include
main()
{
int n=0;
int sum=0;
printf("Enter the values of n\n");
scanf("%d",&n);
while (n>0)
{
sum=sum+n%10;
n=n/10;
}
printf("sum=%d\n",sum);
}

Write a C program to print Subtraction of the given two decimal number

#include

main()
{
int sub=0;
int n=0;
printf("Enter the value of n\n");
scanf("%d",&n);
while(n>0)
{
sub=n%10-sub;
n=n/10;
}
printf("Substraction of the n=%d\n",sub);
}

Write a C program to print multiplication of the given two decimal number

#include

main()
{
int n=0;
int mul=1;
printf("Enter the values of n\n");
scanf("%d",&n);
while (n>0)
{
mul*=n%10;
n=n/10;
}
printf("mul=%d\n",mul);
}

Write a C program to print the rime number upto given number...

#include

main()// Beginnig of the main
{
int prime=0,i=0,j=0,count=0;
printf("Enter the number\n"); // Prompt for input
scanf("%d",&prime);// Takes input form the user

for (i=1; i<=prime ; i++)// Beginning of first FOR loop
{
count=0;
for(j=1;j<=i;j++)// Beginnig of Second FOR loop
{
// printf("ccc%%d",i,j);
if (i%j==0)
{
count++; // or count++
}// End of IF
}//End of the second FOR loop

if (count==2)
{
printf("%d=is a prime number\n",i);
}// End of IF
}// End of the First For loop
}// End of the main

Write a C program to add two matrices & store the results in the 3rd matrix

#include

#include

int main()

{



int p,q;

printf("Enter the order of the matrix Ex:- 2 2 or 3 3\n");

GO:// Goto lable to prompt correct order

scanf("%d%d",&p,&q);



int m = p, n = q;

int a[m][n],b[m][n],c[m][n],i,j,k=0;

if ( m == p && n == q) // checking size

{

printf("Matrix can be added\n");



printf("Enter the Elements to Matrix A\n");

for(i=0;i < m;i++)

{

for(j=0;j < n;j++)

{

printf("A(%d, %d) = ",i,j);

scanf("%d",&a[i][j]);

}

printf("\n");

}

//////////////////////////Add Elements in Array a//////////////////////////////////



printf("Enter the Elements to Matrix B\n");

for(i=0;i < p;i++)

{

for(j=0;j < q;j++)

{

printf("B(%d, %d) = ",i,j);

scanf("%d",&b[i][j]);

}

printf("\n");

}

///////////////////////////Add Elements in Array b/////////////////////////////////





for(i=0;i < m;i++)

for(j=0;j < n;j++)

{

//printf("%d + %d = %d\n",a[i][j],b[i][j],a[i][j]+b[i][j]);

c[i][j]=a[i][j]+b[i][j];

//printf("Sum = %d \n",c[i][j]);



}

///////////////////////////Sum array a and array b into array c/////////////////////////////////

printf("\tSum of two Martices\n\n");

for(i=0;i < m;i++)

{

for(j=0;j < n;j++)

printf("%d\t",c[i][j]);

printf("\n");

}





///////////////////////////Multiplication array a and array b into array c/////////////////////////////////

for(i=0;i < m;i++)

for(j=0;j < n;c[i][j++] = 0);

printf("\nMultiplication of two Martices\n\n");



for(i=0;i < m;i++)

{

for(j=0;j < n;j++)

for(k=0;k < n;k++)

c[i][j] += a[i][k] * b[k][j];

}



for(i=0;i < m;i++)

{

for(j=0;j < n;j++)

printf("%d\t",c[i][j]);

printf("\n\n");

}





}

else

{

printf("Re-Enter correct Order\n");

goto GO;



}

getch();

}

Write a C program To print the Tables for given number

#include

main() // Beginnig of the main block
{
int i =0,n =0; // initialiazation
int count = 0;
printf("Enter the n value\n");
scanf("%d",&n);// Takes input from user
for(i=1;i <=n; i++) // Beginning of the FOR
{
if (n % i == 0)
{
count++;
}
} // End of For

if (count == 2)
{
for (i = 1; i<= 10; i++)
{
printf("\t%d * %d = %d\n",(n*n), i, n*n*i);
}
}
else
{
for (i = 1; i<= 10; i++)
{
printf("\t%d\n",n *i);
}
}

} // End of the main block

******************************OR***********************************
#include

main() // Beginnig of the main block
{
int i=0,n=0; // initialiazation
printf("Enter the n value:");
scanf("%d",&n);// Takes input from user
for (i=1;i<=10;i++) // Beginning of the FOR
{
printf("%d * %d = %d\n",n,i,n*i);
} // End of For

} // End of the main block

Write a C program to Convert the given number into letter... EX: 100----> HUNDRED

#include


int word(int num)
{
int i;
printf("The Number %d is in words --------> ",num);
i=(num/1000000000);
if(i==1)
{
printf(" HUNDRED CRORES");
}

i=((num/100000000)%10);
switch(i)
{
case 1:printf(" TEN CRORES");
break;

case 2:printf(" TWENTY CRORES");
break;

case 3:printf(" THIRTY CRORES");
break;

case 4:printf(" FOURTY CRORES");
break;

case 5:printf(" FIFTY CRORES");
break;

case 6:printf(" SIXTY CRORES");
break;

case 7:printf(" SEVENTY CRORES");
break;

case 8:printf(" EIGHTY CRORES");
break;

case 9:printf(" NINTY CRORES");
break;
}

i=((num/10000000)%10);
switch(i)
{
case 1:printf(" ONE CRORE");
break;

case 2:printf(" TWO CRORES");
break;

case 3:printf(" THREE CRORES");
break;

case 4:printf(" FOUR CRORES");
break;

case 5:printf(" FIVE CRORES");
break;

case 6:printf(" SIX CRORES");
break;

case 7:printf(" SEVEN CRORES");
break;

case 8:printf(" EIGHT CRORES");
break;

case 9:printf(" NINE CRORES");
break;
}

i=((num/1000000)%10);
switch(i)
{
case 1:printf(" TEN LACKS");
break;

case 2:printf(" TWENTY LACKS");
break;

case 3:printf(" THIRTY LACKS");
break;

case 4:printf(" FOURTY LACKS");
break;

case 5:printf(" FIFTY LACKS");
break;

case 6:printf(" SIXTY LACKS");
break;

case 7:printf(" SEVENTY LACKS");
break;

case 8:printf(" EIGHTY LACKS");
break;

case 9:printf(" NINTY LACKS");
break;
}

i=((num/100000)%10);
switch(i)
{
case 1:printf(" ONE LACK");
break;

case 2:printf(" TWO LACKS");
break;

case 3:printf(" THREE LACKS");
break;

case 4:printf(" FOUR LACKS");
break;

case 5:printf(" FIVE LACKS");
break;

case 6:printf(" SIX LACKS");
break;

case 7:printf(" SEVEN LACKS");
break;

case 8:printf(" EIGHT LACKS");
break;

case 9:printf(" NINE LACKS");
break;
}

i=((num/10000)%10);
switch(i)
{
case 1:printf(" TEN THOUSAND");
break;

case 2:printf(" TWENTY THOUSAND");
break;

case 3:printf(" THIRTY THOUSAND");
break;

case 4:printf(" FOURTY THOUSAND");
break;

case 5:printf(" FIFTY THOUSAND");
break;

case 6:printf(" SIXTY THOUSAND");
break;

case 7:printf(" SEVENTY THOUSAND");
break;

case 8:printf(" EIGHTY THOUSAND");
break;

case 9:printf(" NINTY THOUSAND");
break;
}

i=((num/1000)%10);
switch(i)
{
case 1:printf(" ONE THOUSAND");
break;

case 2:printf(" TWO THOUSAND");
break;

case 3:printf(" THREE THOUSAND");
break;

case 4:printf(" FOUR THOUSAND");
break;

case 5:printf(" FIVE THOUSAND");
break;

case 6:printf(" SIX THOUSAND");
break;

case 7:printf(" SEVEN THOUSAND");
break;

case 8:printf(" EIGHT THOUSAND");
break;

case 9:printf(" NINE THOUSAND");
break;
}

i=((num/100)%10);
switch(i)
{
case 1:printf(" HUNDRED");
break;

case 2:printf(" TWO HUNDRED");
break;

case 3:printf(" THREE HUNDRED");
break;

case 4:printf(" FOUR HUNDRED");
break;

case 5:printf(" FIVE HUNDRED");
break;

case 6:printf(" SIX HUNDRED");
break;

case 7:printf(" SEVEN HUNDRED");
break;

case 8:printf(" EIGHT HUNDRED");
break;

case 9:printf(" NINE HUNDRED");
break;
}

i=((num/10)%10);
switch(i)
{
case 1:printf(" TEN");
break;

case 2:printf(" TWENTY");
break;

case 3:printf(" THIRTY");
break;

case 4:printf(" FOURTY");
break;

case 5:printf(" FIFTY");
break;

case 6:printf(" SIXTY");
break;

case 7:printf(" SEVENTY");
break;

case 8:printf(" EIGHTY");
break;

case 9:printf(" NINTY");
break;
}

i=(num%10);
switch(i)
{
case 1:printf(" ONE");
break;

case 2:printf(" TWO");
break;

case 3:printf(" THREE");
break;

case 4:printf(" FOUR");
break;

case 5:printf(" FIVE");
break;

case 6:printf(" SIX");
break;

case 7:printf(" SEVEN");
break;

case 8:printf(" EIGHT");
break;

case 9:printf(" NINE");
break;

}
printf("\n\n");

}
main()
{
int n;
printf("Enter the Number:");
scanf("%d",&n);

word(n);
}

Write a C program to convert Decimal to binary.. Ex: 7---111.

#include

int dec_bin(int n)// function Definition
{
int array[10],i=0; // variable declaration and initialization
while(n>0) // iterate till the n value > 0
{
array[i++] = n%2; // store each reaminder into array
n=n/2; // division
}
while(i>0) // iterate till the condition remains true
printf("%d", array[--i]); // printing the elements from the last index
printf("\n");
} // dec_bin End

main()//Main function begining
{
int n=0;
printf("Please Enter any possitive number :");
scanf("%d",&n);
dec_bin(n);//function calling
}// Main function Ending

Write a C Program to convert Binary ot Decimal.. Ex: 1100---12

#include
#include

char bin_dec(char bin[])
{
int sum =0,n=1,length=0;

length = strlen(bin);
while(length>0)
{
if(bin[--length]== '1') // if bin index value == to 1
sum +=n; // Add n value to sum
n*=2; // Division with
}
printf("Binary to Decimal = %d\n",sum);

}
main()
{
char bin[10];
printf("Enter any positive number:");
scanf("%s",bin);

bin_dec(bin);//funciton calling. Passing Argument of type char array
}

Write a C program to get ARMSTRONG numbers upto given number

#include
#include
main()
{
int n=1000;
int a,b,c,d;
printf("Armstrong numbers upto 1000 are:\n");
for(a=1;a<=n;a++)
{
b=a;
d=0;
while(b>0)
{
c=b%10;
d=d+pow(c,3);
b=b/10;
}
if(d==a)
printf("\t%d\n",a);
}
}

Define the structure called student having properties like stud_id, stud_name, stud_branch,and email_add. Write a program which takes the details of

#include

#include

#define SIZE 3

#include

struct student

{

char *stud_id;

char *stud_name;

char *stud_branch;

char *email_add;

}*s;



main()

{

int i = 0;



s = (struct student *)malloc(80);

for(i = 0; i < SIZE; i++)

{

(s+i)->stud_id = (char *)malloc(30);

(s+i)->stud_name = (char *)malloc(30);

(s+i)->stud_branch = (char *)malloc(30);

(s+i)->email_add = (char *)malloc(30);



printf(" +--------------------------------------------------------------+\n |\t\t\tPlease Enter Student %d Details\t\t|\n +--------------------------------------------------------------+\n",i+1);

printf("\nEnter Student ID :");

scanf("%s",(s+i)->stud_id);



printf("\nEnter Student Name :");

scanf("%s",(s+i)->stud_name);



printf("\nEnter Student Branch :");

scanf("%s",(s+i)->stud_branch);



printf("\nEnter Student Address :");

scanf("%s",(s+i)->email_add);

}

for(i = 0; i < SIZE; i++)

{

printf(" \n+------------------------------------------------------------+\n|\t\t\tStudent %d Details\t\t |\n +------------------------------------------------------------+\n",i+1);

printf("\t\nStudent ID :%s",(s+i)->stud_id);

printf("\t\nStudent Name :%s",(s+i)->stud_name);

printf("\t\nStudent Branch :%s",(s+i)->stud_branch);

printf("\t\nStudent Address :%s",(s+i)->email_add);

}



}

A) Write a program to accept the string and display the reverse of that string using pointers(without using strrev() function)? B) Write a progra

#include

#include

char StringReverse(char *str)

{

int length = strlen(str);

int Found = 1;

while( length-- > 0)

{

printf("%c",str[length]);

if( (str[length] != str[strlen(str) -1 - length] ) && Found == 1 )

Found = 0;

}

if (Found) printf(" ) Is Palindrome String\n");

else printf(" )Is Not Palindrome String\n");

}



main()

{

char *str;

str = (char *)malloc(20);// Dynamic Memory Allocation

printf("Please Enter the String\n");

scanf("%s",str);

printf("Reverse of ( %s = ",str);

StringReverse(str);



}

Write a program to accept two integer numbers and swap those two integer numbers using pointers?

#include
int swap(int *x, int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
main()
{
int a,b;
printf("Enter any two numbers:");
scanf("%d%d",&a,&b);
printf("Before Swapping ------> %d %d\n",a,b);
swap(&a,&b);
printf("After Swapping -------> %d %d\n",a,b);

}

Define the structure called Batsman having properties like Batsman_ name,Batsman_country and Bats_avg .Using Batsman declare an array PLAYER with 11

#include

struct Batsman
{
char Batsman_name[30];
char Batsman_country[30];
float Bats_avg;

};
main()
{
int n,i;
char country[30];
printf("Enter How many Players details are you wishing:");
scanf("%d",&n);

struct Batsman PLAYER[n];
printf("Please Enter %d Details of Players\n\n",n);
for(i=0;i {
printf("Enter the Batsman_Name : ");
scanf("%s",PLAYER[i].Batsman_name);
putchar('\n');
printf("Enter the Batsman_Country :");
scanf("%s",PLAYER[i].Batsman_country);
putchar('\n');
printf("Enter the Batsman_Average :");
scanf("%f",&PLAYER[i].Bats_avg);
putchar('\n');
}
printf("************************************************************\n");
printf("Enter the Country :");
scanf("%s",country);
putchar('\n');
for(i=0;i {
if(strcmp(country,PLAYER[i].Batsman_country)==0)
{
printf("Name : %s\n",PLAYER[i].Batsman_name);
printf("Average : %f\n",PLAYER[i].Bats_avg);
putchar('\n');

}
}

}

Define the structure called Employee having properties like emp_id, emp_name, gender, and emp_sal email_add. Write a program which takes the details o

#include

struct Employee
{
int emp_id;
char emp_name[30];
char gender[10];
int emp_sal;
char email_add[50];
};

main()
{
struct Employee d[100];
int i,n;
printf("Enter the Number of Employees Details: ");
scanf("%d",&n);
for(i=0;i {
printf("Enter the ID of Employ:");
scanf("%d",&d[i].emp_id);

printf("Enter the name of the Employ:");
scanf("%s",d[i].emp_name);

printf("Enter the gender:");
scanf("%s",d[i].gender);

printf("Enter the Salory:");
scanf("%d",&d[i].emp_sal);

printf("Enter the Email ID :");
scanf("%s",d[i].email_add);

printf("\n\n");

}
for(i=0;i printf("\n\n\nEmploy's ID-----> %d\nEmploy's Name-----> %s\nEmploy's Gender-------> %s\nEmploy's Salary-------> RS. %d\nEmploy's Email ID-----> %s\n\n",d[i].emp_id,d[i].emp_name,d[i].gender,d[i].emp_sal,d[i].email_add);

}

Define the structure called CLASS having properties like stud_id, stud_name and stud_branch. Write a program which takes the details of at least 15

#include
struct CLASS{
char stud_name[20];
int stud_ID[10];
char stud_Branch[20];
};
main()
{
int i,m;
struct CLASS student[15];
printf("How many students details do you want to enter? ");
scanf("%d",&m);
for (i=0;i{
printf("Enter the details of %d student\n",i+1);
printf("Enter the name of student: ");
scanf("%s",student[i].stud_name);

printf("Enter students ID ");
scanf("%d",student[i].stud_ID);

printf("Enter students Branch ");
scanf("%s",student[i].stud_Branch);

}
printf("Thank you\n");
}

Find the sum of all odd no.’s from 0 to 100 using function recursion.

#include
int odd(int n,int sum)
{
if (n%2==1)
sum = sum+n;
if (n==100)
return sum;
return odd(n+1,sum);
}
main()
{
printf("sum is %d\n",odd(1,0));
}

Find the sum of all even no.’s from 0 to 100 using function recursion.

#include
int even(int n,int sum)
{
if (n%2==0)
sum = sum+n;
if (n==100)
return sum;
return even(n+1,sum);
}
main()
{
printf("sum is %d\n",even(1,0));
}

Write a general-purpose function to convert any given year into its roman equivalent. The following table shows the roman equivalents of decimal numb

#include

int roman(int year)
{
int i;
printf("The year %d is converted to Roman------->",year);
i=(year/1000);
while(i)
{
printf("m");i--;
}

i=((year/100)%10);
switch(i)
{
case 1:printf("c");
break;

case 2:printf("cc");
break;

case 3:printf("ccc");
break;

case 4:printf("cd");
break;

case 5:printf("d");
break;

case 6:printf("dc");
break;

case 7:printf("dcc");
break;

case 8:printf("dccc");
break;

case 9:printf("cm");
break;
}

i=((year/10)%10);
switch(i)
{
case 1:printf("x");
break;

case 2:printf("xx");
break;

case 3:printf("xxx");
break;

case 4:printf("xl");
break;

case 5:printf("l");
break;

case 6:printf("lx");
break;

case 7:printf("lxx");
break;

case 8:printf("lxxx");
break;

case 9:printf("xc");
break;
}

i=(year%10);
switch(i)
{
case 1:printf("i");
break;

case 2:printf("ii");
break;

case 3:printf("iii");
break;

case 4:printf("iv");
break;

case 5:printf("v");
break;

case 6:printf("vi");
break;

case 7:printf("vii");
break;

case 8:printf("viii");
break;

case 9:printf("ix");
break;
}
printf("\n\n");

}

main()
{
int year;
printf("Enter any year:");
scanf("%d",&year);

roman(year);
}

*************************OR*****************************************
#include
#include

void roman(char *s, unsigned n)
/* Writes the Roman numeral representing n into the buffer s.
Handles up to n = 3999. Since C doesn't have exceptions, n = 0
causes the whole program to exit unsuccessfully. s should be
have room for at least 16 characters, including the trailing
null. */
{if (n == 0)
{puts("Roman numeral for zero requested.");
exit(EXIT_FAILURE);}

#define digit(loop, num, c) \
loop (n >= num) \
{*(s++) = c; \
n -= num;}
#define digits(loop, num, c1, c2) \
loop (n >= num) \
{*(s++) = c1; \
*(s++) = c2; \
n -= num;}

digit ( while, 1000, 'M' )
digits ( if, 900, 'C', 'M' )
digit ( if, 500, 'D' )
digits ( if, 400, 'C', 'D' )
digit ( while, 100, 'C' )
digits ( if, 90, 'X', 'C' )
digit ( if, 50, 'L' )
digits ( if, 40, 'X', 'L' )
digit ( while, 10, 'X' )
digits ( if, 9, 'I', 'X' )
digit ( if, 5, 'V' )
digits ( if, 4, 'I', 'V' )
digit ( while, 1, 'I' )

#undef digit
#undef digits

*s = 0;}

int main(void)
{char buffer[16];
int i;
for ( i = 1 ; i < 1000 ; ++i)
{roman(buffer, i);
printf("%4d: %s\n", i, buffer);}
return 1;}

Write a function thar calculates arithmetic addition,subtraction,multiplication and division of two integers.

#include
int addition(int a,int b)
{
printf("\nAddition of %d and %d is %d\n",a,b,a+b);
}
int subtraction(int a,int b)
{
printf("\nSubtraction of %d and %d is %d\n",a,b,a-b);
}
int multiplication(int a,int b)
{
printf("\nmultiplication of %d and %d is %d\n",a,b,a*b);
}
int division(int a,int b)
{
printf("\nDivision of %d and %d is %d\n",a,b,a/b);
}
main()
{
int choice;
do{
int n,m;
printf("For Addition press-----> <1>\nFor Subtraction press-------> <2>\nFor Multiplication Press------> <3>\nFor Division press--------> <4>\n");
printf("Enter Your choice:");
scanf("%d",&choice);

switch(choice)
{
case 1: printf("Enter any two integers:");
scanf("%d%d",&n,&m);
addition(n,m);
break;

case 2: printf("Enter any two integers:");
scanf("%d%d",&n,&m);
subtraction(n,m);
break;

case 3: printf("Enter any two integers:");
scanf("%d%d",&n,&m);
multiplication(n,m);
break;
case 4: printf("Enter any two integers:");
scanf("%d%d",&n,&m);
division(n,m);
break;
default:printf("WOOOWW......... InValid choice...");

}
printf("\nTo Continue Please Press <1>\n");
scanf("%d",&choice);

}while(choice==1);
printf("I AM CRAZY ABOUT YOU.....\n");

}

Write a function to obtain the prime factors of this number. For example, prime factors of 24 are 2, 2, 2 and 3, whereas prime factors of 35 are 5 an

#include

// The following Function detects a Prime number.
int prime(int num)
{
int i,ifprime;
for(i=2;i<=num-1;i++)
{
if(num%i==0)
{
ifprime=0;
}
else
ifprime=1;
}
return (ifprime);
}


// The following function prints the prime factors of a number.
int prime_factor(int num)
{
int factor,ifprime;
for(factor=2;factor<=num;)
{
prime(factor);// so that the factors are only prime and nothing else.
if(ifprime)
{
if(num%factor==0)// dividing by all the prime numbers less than the number itself.
{
printf("%d\n",factor);
num=num/factor;
continue;
}
else
{
factor++;//this cannot be made a part of the for loop
}

}

}


}

main()
{
int n;
printf("Enter the number:");
scanf("%d",&n);

prime_factor(n);
}

****************************OR**********************************

#include
void primefactors(int n)
{
int i,j,count=0;
for (i=1;i<=n;i++)
{
if (n%i==0){


for (count=0,j=1;j<=i;j++)
{
if (i%j==0)
++count;
}
if (count==2)
printf("%d\n",i);
}
}
}
main()
{
int n;
printf("Enter the number ");
scanf("%d",&n);
primefactors(n);
}

Write a function which receives a float and an int from main(), finds the product of these two numbers and returns the product which is printed throu

#include

int product(int(x),float (y))
{
float p = x*y;
printf("The Product of %d and %f is %f\n\n",x,y,p);
}

main()
{
int n;
float m;
printf("Enter Any two numbers:");
scanf("%d%f",&n,&m);

product(n,m);
}

Write a function that calculates both Area and Perimeter/Circumference of the Circle,whose Radius is entered through the keyboard....

#include
#define PI 3.14

int circle(int r)
{
float Area = PI*(r*r);
printf("\nArea of Cirlce = %f\n",Area);
}
int Perimeter(int r)
{
float Perimeter = 2*PI*r;
printf("\nPerimeter of Circle = %f\n",Perimeter);
}
main()
{
int choice;
do
{
int radius;
printf("Press 1 for Area and 2 for Perimeter\n");
printf("Please Enter your Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the Radius for Area:");
scanf("%d",&radius);
circle(radius);
break;
case 2:
printf("Enter the Radius for Perimeter:");
scanf("%d",&radius);
Perimeter(radius);
break;
default:
printf("Please Enter valid Choice...");
}
printf("\nPress 1 to continue...\nPress Other to Exit..\n");
scanf("%d",&choice);
}while(choice==1);
printf("HEY NAUGHTY SEE YOU SOON.....\n\n");
}

*************************OR******************************************************
#include
float area(float n)
{
float pi=3.14;
return pi*n*n;
}
float circum(float a)
{
float pi=3.14;
return 2*pi*a;
}
main()
{
float radius;
printf("Enter the radius here ");
scanf("%f",&radius);
printf("area is %f and perimeter is %f\n",area(radius),circum(radius));
}

Read in an integer n, read in n integers and print the integer with the highest frequency.

#include
#include

int frequent(int arr[],int n)
{
int i,j,k,m,count;
int b[20],c[20];

for (j=0;j {

for (count=0,i=0;i {
if (arr[i]==arr[j])
++count;
}
b[j]=count;
printf("%d",b[j]);
}
for (i=0;i{
c[i] = b[i];
}
for (i=0;i{
if (c[i]>c[i+1]){
for (j=0;j {
if (b[j]==c[i])
{
printf("Maximum is %d\n",arr[j]);
}
else
printf("Maximum is at both %d and %d\n",arr[j],arr[i]);
}
}
}

}


main()
{
int i,j,k,n,arr[20];
printf("Enter the number of elements ");
scanf("%d",&n);
for (i=0;i{
printf("a[%d]=",i);
scanf("%d",&arr[i]);
}
frequent(arr,n);
}

Write a C program that reads an integer n and uses an array to efficiently find out the first n prime numbers.

#include
int prime(int n)
{
int i,j,arr[200],count;
for (i=0;i<200;i++)
arr[i]=i+1;
for (i=0;i{
for (j=1,count=0;j<=arr[i];j++){
if (arr[i]%j==0)
++count;
}
if (count==2)
printf("%d\n",arr[i]);
}
}
main()
{
int n;
printf("Enter the number to which prime numbers are to be printed ");
scanf("%d",&n);
prime(n);
}

Write a C program to check given number palidrome or not?

#include
int rev(int a);

int main()
{
int num,result;
printf("Enter a four digit number:");
scanf("%d",&num);

result =rev(num);
printf("%d revers number = %d \n",num,result);

if (result == num)
printf("palindrome\n");
else
printf("not palidrome\n");
return 0;
}
int rev(int a)
{
int res=0;
while(a>0)
{
res = res*10+a%10;
a=a/10;
}
return res;
}

How to find LCM...?

#include
int find_lcm(int a,int b);

int main()
{
int a,b;
printf("Enter 'a' value:");
scanf("%d",&a);

printf("Enter 'b' value:");
scanf("%d",&b);

printf("\nlcm of %d and %d =%d\n",a,b,find_lcm(a,b));
return 0;
}

int find_lcm(int a, int b)
{
int i;
for(i=1;i<=a*b;i++)
if(i%a = 0 && i%b == 0)
return i;
}

Sunday, November 21, 2010

Write a C program to generate and print the first N Fibonacci numbers

#include
int fibonacci(int n);
int main()
{
int n,i;
printf("Enter 'n' value:");
scanf("%d",&n);
for(i=0;i<=n;i++)
printf("%d",fibonacci(i));
printf("\n");
return 0;
}
int fibonacci(int n)
{
if(n == 0)
{
return n;
}
else if(n== 1|| n==2)
{

return 1;
}
else
{
return fibonacci(n-1)+fibonacci(n-2);
}
}

Find the GCD of given two numbers.

#include
int fib_gcd(int a,int b);
int main()
{
int a,b;
printf("Enter 'a' value:");
scanf("%d",&a);

printf("Enter 'b' value:");
scanf("%d",&b);

printf("Gcd of %d and %d =%d\n",a,b,find_gcd(a,b));
}

int find_gcd(int a, int b)
{
int temp;
while(b!=0)
{
temp =a%b;
a=b;
b=temp;
}
return a;
}

------------------OR----------------------------------

#include
main()
{
int a,b,i,m=0;
printf("Enter any two values:");
scanf("%d %d",&a,&b);

int limit=a>b?a:b;
int small=a for(i=1;i {
if(a%i==0 && b%i==0)
m=i;
if(m>small)
break;
}
printf("gcd= %d\n",m);
}

Write C program to print a. Integers from 1-100 b. Even numbers from 1-100 c. Odd numbers from 1-100

int i = 0,j = 0;
short k = 0;

int Integers(int no)
{
printf("+----------------------------+\n\tIntegers\n+----------------------------+\n");
for(i = 1; i < no; i++)
{
printf("%d ",i);
if(i - j == 10)
{
printf("\n----------------------------+\n");
j = i;
}
}
}

int Even_numbers(int no)
{
j = 0;
printf("----------------------------+\n\tEven Numbers\n----------------------------+\n");
for(i = 0; i < no; i+=2)
{
printf("%d ",i);
if(i - j == 20)
{
printf("\n----------------------------+\n");
j = i;
}
}
}

int Odd_numbers(int no)
{
j = 1;
printf("----------------------------+\n\tOdd Numbers\n----------------------------+\n");
for(i = 1; i < no; i+=2)
{
printf("%d ",i);
if(i - j == 20)
{
printf("\n----------------------------+\n");
j = i;
}
}
}


main()
{

int choice = 0,a = 0;// variable declaration and initialization
printf("Size of Char %d\n",sizeof(int short));
do // do-while loop
{
printf("\nPlease Enter Any +ve No\n");
scanf("%d",&a);

printf("\nTo Print 1-100 Press --> 1\nTo Print Even numbers from 1-100 Press --> 2\nTo Print Odd numbers from 1-100 Press --> 3\n");

printf("Enter Your Choice --> ");
scanf("%d",&choice);
switch(choice)
{
case 1:
Integers(a);// Function Calling
break;

case 2:
Even_numbers(a);// Function Calling
break;

case 3:
Odd_numbers(a);// Function Calling
break;

default:
printf("Please Enter the Valid Choice\n");
}// switch
printf("\n\nTo Continue Press 1 Else Other to Exit\n");
scanf("%d",&choice);
} while(choice == 1);
printf("Bye......\n");
}

Write a C program to find following parameters for known 3 numbers. a. Sum b. Average c. Min d. Max e. Variance f. Standard deviation

#include
#include
float Sum(float a, float b, float c);
float Avg(float a, float b, float c);
float Min(float a, float b);
float Max(float a, float b);
float Vari(float a, float b, float c);
float SD(float a, float b, float c);
float input(float temp);

int main()
{
float a,b,c;

printf("Enter 'a' value: ");
a = input(a);

printf("Enter 'b' value: ");
b = input(b);

printf("Enter 'c' value: ");
c = input(c);

printf("\nSum of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Sum(a,b,c));
printf("Avg of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Avg(a,b,c));
printf("Min of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Min(Min(a,b),c));
printf("Max of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Max(Max(a,b),c));
printf("\nVariance of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Vari(a,b,c));
printf("Standard deviation of %.1f, %.1f and %.1f = %.1f\n",a,b,c,SD(a,b,c));

return 0;
}
float input(float temp)
{
scanf("%f",&temp);
return temp;
}
float Sum(float a, float b, float c)
{
return (a+b+c);
}
float Avg(float a, float b, float c)
{
return (Sum(a,b,c)/3);
}
float Min(float a, float b)
{
float x;
x = (a <= b) ? a : b; return x; } float Max(float a, float b) { float x; x = (a >= b) ? a : b;
return x;
}
float Vari(float a, float b, float c)
{
float x,y,z;
x = pow((a - Avg(a,b,c)),2);
y = pow((b - Avg(a,b,c)),2);
z = pow((c - Avg(a,b,c)),2);

return Avg(x,y,z);
}
float SD(float a, float b, float c)
{
return sqrt(Vari(a,b,c));
}

Write C program to print a.Integers from 1-100 b.Even numbers from 1-100 c.Odd numbers from 1-100

#include
void Integers();
void Even();
void Odd();

int main()
{
Integers();
Even();
Odd();
return 0;
}
void Integers()
{
int i;
printf("\nIntegers from 1-100\n");
for(i = 1 ;i <= 100 ; i++)
{
printf("%d\n",i);
}
}
void Even()
{
int i;
printf("Even numbers from 1-100\n");
for(i = 1 ;i <= 100 ; i++)
{
if( i % 2 == 0)
printf("%d\n",i);
}
}
void Odd()
{
int i;
printf("Odd numbers from 1-100\n");
for(i = 1 ;i <= 100 ; i++)
{
if( i % 2 != 0)
printf("%d\n",i);
}
}

Write a C program to find the roots of a quadratic equation.

#include
#include
void roots(float a, float b, float c);

int main()
{
float a,b,c;
printf("Enter a value: ");
scanf("%f",&a);
printf("Enter b value: ");
scanf("%f",&b);
printf("Enter c value: ");
scanf("%f",&c);


printf("The quadratic equation is: (%.1f) x^2 + (%.1f) x + (%.1f) \nRoots for the above equation are: ",a,b,c);
roots(a,b,c);


return 0;
}
void roots(float a, float b, float c)
{
if((pow(b,2) - (4 * a * c)) < 0)
{
printf("\nRoots are complex numbers \n");
}
else
{
printf("\nRoot1 = %.2f",(((-1 * b) + sqrt((pow(b,2) - (4 * a * c))))/2*a));
printf("\nRoot2 = %.2f\n",(((-1 * b) - sqrt((pow(b,2) - (4 * a * c))))/2*a));
}
}

A rectangle with sides parallel to the X- and Y-axes is specified by four real numbers a, b, c, and d. Assume that a <= c and b <= d. The four corners

#include
int check_sides(float w, float x, float y, float z);
float input(float temp);
void check_intersect(float a1, float b1, float c1, float d1,float a2, float b2, float c2, float d2);
int main()
{

float a1,b1,c1,d1;
float a2,b2,c2,d2;


printf("\nEnter first rectangle side values: \n\n");
printf("Enter 'a1' value: ");
a1 = input(a1);

printf("Enter 'b1' value: ");
b1 = input(b1);

printf("Enter 'c1' value: ");
c1 = input(c1);

printf("Enter 'd1' value: ");
d1 = input(d1);

printf("\nEnter second rectangle side values: \n\n");
printf("Enter 'a2' value: ");
a2 = input(a2);

printf("Enter 'b2' value: ");
b2 = input(b2);

printf("Enter 'c2' value: ");
c2 = input(c2);

printf("Enter 'd2' value: ");
d2 = input(d2);


if(check_sides(a1,b1,c1,d1) && check_sides(a2,b2,c2,d2))
{
printf("\n** Four corners of the first rectangle are: ** \n");
printf("(%.1f,%.1f) [bottom left] \n",a1,b1);
printf("(%.1f,%.1f) [bottom right]\n",c1,b1);
printf("(%.1f,%.1f) [top left] \n",a1,d1);
printf("(%.1f,%.1f) [top right] \n",c1,d1);

printf("\n** Four corners of the second rectangle are: ** \n");
printf("(%.1f,%.1f) [bottom left] \n",a2,b2);
printf("(%.1f,%.1f) [bottom right]\n",c2,b2);
printf("(%.1f,%.1f) [top left] \n",a2,d2);
printf("(%.1f,%.1f) [top right] \n",c2,d2);

check_intersect(a1,b1,c1,d1,a2,b2,c2,d2);

}
else
printf("Invalid sides\n");

}
void check_intersect(float a1, float b1, float c1, float d1,float a2, float b2, float c2, float d2)
{
if((a1 <= c2 && a2 <= c1) || (b1 <= d2 && b2 <= d1))
{
printf("\nR1 and R2 rectangles are intersect \n");
}
else
printf("\nR1 and R2 rectangles aren't intersect \n");
}

float input(float temp)
{
scanf("%f",&temp);
return temp;
}
int check_sides(float w, float x, float y, float z)
{
int a;
a = (w <= y && x <= z) ? 1: 0;
return a;
}

Write a C program to find the Area and perimeter of a. Circle Input: r (radius) per = 2 pi*r, area = pi r^2 b. Square Input: a (length of

#include
#include
#define PI 3.147

int Circle(int r)
{
printf("Area of Circle = %f\n",PI * (r*r));
printf("Perimeter of Circle = %f\n",2 *PI * r);
}
/**********************************************************************************************/
int Square(int side)
{
printf("Area of Square = %d\n",side * side);
printf("Perimeter of Square = %d\n",4 * side);
}
/**********************************************************************************************/
int Triangle(int a,int b,int c)
{
float s = (a + b + c) / 2;
float area = (float) ( sqrt (s * (s-a) * (s-b) * (s-c)));
printf("Area of Triangle = %.1f\n",area);
printf("Perimeter of Triangle = %.1f\n",s);
}
/**********************************************************************************************/
int Rectangle(int length,int width)
{
printf("Area of Rectangle = %d\n",length * width);
printf("Perimeter of Rectangle = %d\n",2 * (length + width) );
}
/**********************************************************************************************/
int Ellipse(int x,int y)
{
printf("Area of Ellipse = %f\n",PI * x * y);
printf("Perimeter of Ellipse = %f\n",(float)(2 * PI * sqrt(x*x + y*y)));
}
/**********************************************************************************************/

main() // Beginning of Main Function
{

int choice = 0,a = 0,b = 0,c = 0;


do
{

printf("For Circle Press <>\nFor Square Press <>\nFor Triangle Press <>\nFor Rectangle Press <>\nFor Ellipse Press <>\n---------------------------\n");

printf("Enter Your Choice --> ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Please Enter Radius of Circle\n");
scanf("%d",&a);
Circle(a);
break;
case 2:
printf("Please Enter Side of Square\n");
scanf("%d",&a);
Square(a);
break;
case 3:
printf("Please Enter Sides of Triangle (like 1 2 3)\n");
scanf("%d%d%d",&a,&b,&c);
Triangle(a,b,c);
break;
case 4:
printf("Please Enter Length & Breadth of Rectangle\n");
scanf("%d%d",&a,&b);
Rectangle(a,b);
break;
case 5:
printf("Please Enter Two Axes of Ellipse (like 2 3)\n");
scanf("%d%d",&a,&b);
Ellipse(a,b);
break;
default:
printf("Please Enter the Valid Choice\n");
}// switch
printf("To Continue Press 1 Else Other to Exit\n");
scanf("%d",&choice);
} while(choice == 1);
printf("Bye......\n\n");
}// End of Main

Write a C program to generate all the prime numbers between 1 and n, where n is a positive integer.

int no_of_primes(int n)// Function Definition
{
int prime = 0,range = 1,count_remainder = 0,count_primes = 0;

printf("-------------------------------------\nPrime Numbers Below %d\n-------------------------------------\n",n);
while ( prime < n)
{ count_remainder = 0;
for (range = 1; range <=prime; range++)
if (prime % range == 0)
count_remainder++;
if (count_remainder == 2)
{
printf("\t%d\n",prime);
count_primes++;
}
prime++;
}
printf("-------------------------------------\nNo of Primes Between %d and %d = %d\n-------------------------------------\n",1,n,count_primes);


}
/**********************************************************************************************/


main() // Beginning of Main Function
{

int no = 0;
printf("Please Enter Any Positive Integer\n");
scanf("%d",&no);
no_of_primes(no); // Function Calling by passing an argument as "no"

}// End of Main

Write a C program to find the sum, multiplication, division, subtraction of individual digits of a positive integer.

int get_digits(int);// Function Prototype
/**********************************************************************************************/

main() // Beginning of Main Function
{

int no = 0;
printf("Please Enter Any Positive Integer\n");
scanf("%d",&no);
get_digits(no); // Function Calling by passing an argument as "no"

}// End of Main
/**********************************************************************************************/
int get_digits(int n)// Function Definition
{
int sum,mult,sub,remainder;
sum = sub = remainder = 0;
mult = 1;
double division = 1;
int temp = n;
while ( n > 0)
{
remainder = n % 10;

sum = sum + remainder;
sub = remainder - sub;
mult = mult * remainder;
division = division / (double)remainder;// type conversion remainder of type int
n = n / 10; //into double
}// WHILE

printf("---------------------------------------------\nSum of Digits of \t%11d = %d\n",temp,sum);
printf("Subtraction of Digits of \t%3d = %d\n",temp,sub);
printf("Multiplication of Digits of \t%3d = %d\n",temp,mult);
printf("Divsion of Digits of \t%11d = %lg\n---------------------------------------------\n\n",temp,division);
}

Saturday, November 20, 2010

Write a C program to print following sentences. a. I am an Indian b. “I am an Indian” c. *I am an Indian*

#include

main() // Beginning of Main Function
{

printf("I am Indian\n");
printf("\"I am Indian\"\n");
printf("*I am Indian*\n");
}// End of Main