Friday, October 14, 2011

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

#include //This is include information about standard library
main() //User define function
{
printf("I am an Indian\n"); //here printing the given sentence
printf("*I am an Indian*\n"); //here printing the given sentence
printf("\"I am an Indian\"\n"); //here printing the given sentence
}

Define the structure called Batsman having properties like Batsman_ name,Batsman_country and Bats_avg .Using Batsman declare an array PLAYER with 11 elements and write a program to read the information of all the 11 Players and print Country wise list containing names of batsman with their batting averages.

#include
main()
{
struct Batsman
{
char Batsman_name[30];
char Batsman_country[10];
float Batsman_avg;
};

struct Batsman PLAYER[3];
char temp[1];
int i,j,k,l,m;
for (i=0;i<11;i++)
{
printf("Enter Batsman name: ");
gets(PLAYER[i].Batsman_name);
printf("Enter Batsman Country: ");
gets(PLAYER[i].Batsman_country);
printf("Enter Batsman Average: ");
scanf("%f",&PLAYER[i].Batsman_avg);
gets(temp);
}
for(j=0;j<11;j++)
{
m=0;
for(k=0;k if(strcmp(PLAYER[j].Batsman_country,PLAYER[k].Batsman_country)==0)
{
m++;
break;
}
if (m==0)
{
printf("\fCountry '%s' batsman are :-\n\n",PLAYER[j].Batsman_country);
for(l=0;l<11;l++)
if(strcmp(PLAYER[j].Batsman_country,PLAYER[l].Batsman_country)==0)
{
printf("%s\t",PLAYER[l].Batsman_name);
printf("%s\t",PLAYER[l].Batsman_country);
printf("%.4f",PLAYER[l].Batsman_avg);
printf("\n");
}
}
}

}
#include
main()
{
int i,n;
struct {
char emp_id[10];
char emp_name[10];
char emp_gen[10];
int emp_sal;
char email_add[30];
}
Employee[50];
for(i=0;i<10;i++)
{
printf("\n\nEnter Employee id:\t");
scanf("%s",Employee[i].emp_id);
printf("Enter Employee name:\t");
scanf("%s",Employee[i].emp_name);
printf("Enter Employee gender:\t");
scanf("%s",Employee[i].emp_gen);
printf("Enter Employee sal:\t");
scanf("%d",&Employee[i].emp_sal);
printf("Enter Employee email:\t");
scanf("%s",Employee[i].email_add);
}
for(i=0;i<10;i++)
{
printf("\n\nEmployee id : \t%s\n",Employee[i].emp_id);
printf("Employee name : \t%s\n",Employee[i].emp_name);
printf("Employee gender : \t%s\n",Employee[i].emp_gen);
printf("Employee salary : \t%d\n",Employee[i].emp_sal);
printf("Employee email : \t%s\n\n\n",Employee[i].email_add);
}
}

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 of 10 employees.

#include
main()
{
int i,n;
struct {
char emp_id[10];
char emp_name[10];
char emp_gen[10];
int emp_sal;
char email_add[30];
}
Employee[50];
for(i=0;i<10;i++)
{
printf("\n\nEnter Employee id:\t");
scanf("%s",Employee[i].emp_id);
printf("Enter Employee name:\t");
scanf("%s",Employee[i].emp_name);
printf("Enter Employee gender:\t");
scanf("%s",Employee[i].emp_gen);
printf("Enter Employee sal:\t");
scanf("%d",&Employee[i].emp_sal);
printf("Enter Employee email:\t");
scanf("%s",Employee[i].email_add);
}
for(i=0;i<10;i++)
{
printf("\n\nEmployee id : \t%s\n",Employee[i].emp_id);
printf("Employee name : \t%s\n",Employee[i].emp_name);
printf("Employee gender : \t%s\n",Employee[i].emp_gen);
printf("Employee salary : \t%d\n",Employee[i].emp_sal);
printf("Employee email : \t%s\n\n\n",Employee[i].email_add);
}
}
#include
main()
{
int i,n;
struct {
char emp_id[10];
char emp_name[10];
char emp_gen[10];
int emp_sal;
char email_add[30];
}
Employee[50];
for(i=0;i<10;i++)
{
printf("\n\nEnter Employee id:\t");
scanf("%s",Employee[i].emp_id);
printf("Enter Employee name:\t");
scanf("%s",Employee[i].emp_name);
printf("Enter Employee gender:\t");
scanf("%s",Employee[i].emp_gen);
printf("Enter Employee sal:\t");
scanf("%d",&Employee[i].emp_sal);
printf("Enter Employee email:\t");
scanf("%s",Employee[i].email_add);
}
for(i=0;i<10;i++)
{
printf("\n\nEmployee id : \t%s\n",Employee[i].emp_id);
printf("Employee name : \t%s\n",Employee[i].emp_name);
printf("Employee gender : \t%s\n",Employee[i].emp_gen);
printf("Employee salary : \t%d\n",Employee[i].emp_sal);
printf("Employee email : \t%s\n\n\n",Employee[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 students.

main()
{
int i,n;
struct {
char stud_id[30];
char stud_name[30];
char stud_branch[30];
}
class[50];
printf("\nHow many students details would you want in the class(enter 15<) :\t");
scanf("%d",&n);
for(i=0;i {
printf("\n\nEnter student id:\t");
scanf("%s",class[i].stud_id);
printf("Enter student name:\t");
scanf("%s",class[i].stud_name);
printf("Enter student branch:\t");
scanf("%s",class[i].stud_branch);
}
printf("\n\n");
for(i=0;i {
printf("student id :\t\t %s\n",class[i].stud_id);
printf("student name :\t\t %s\n",class[i].stud_name);
printf("student branch :\t %s\n\n\n",class[i].stud_branch);
}
}

Write a function that calculates arithmetic addition, subtraction, multiplication and division of two integers?

#include
int addition(int x, int y)
{
int sum=x+y;
return sum;
}
int substraction(int x, int y)
{
int sub =x-y;
return sub;
}
int multiplication(int x, int y)
{
int mul =x*y;
return mul;
}
float division(float x,float y)
{
float div =(x/y);
return div;
}
main()
{
int a, b;
printf("\nEnter 1st integer:\t");
scanf("%d",&a);
printf("Enter 1st integer:\t");
scanf("%d",&b);
printf("\naddition :\t\t%d\n",addition(a,b));
printf("substraction :\t\t%d\n",substraction(a,b));
printf("multiplication :\t%d\n",multiplication(a,b));
printf("division :\t\t%.2f\n\n",division(a,b));
}