Posts

My Subject Blog

C program to Find Total of Marks using Structure

/* Write a function to enter Roll no, marks of the three subject for 3 students and find total obtained by each student. */ #include <stdio.h> struct student { int rollno; int marks[3]; }s[3]; int main(void)  { int i,j,total=0; for(i=0;i<3;i++) { total=0; printf("Enter Roll No : "); scanf("%d",&s[i].rollno); for(j=0;j<3;j++) { printf("Enter Marks for Subject [%d]",j+1); scanf("%d",&s[i].marks[j]); total=total+s[i].marks[j]; } printf("\n Total Marks of Student Roll No [%d] : %d",s[i].rollno,total); } return 0; }

C Program to define structure called Cricket

/* Define a structure called cricket that will describe the following information:  a. Player name  b. Team name  c. Batting average */ struct cricket { char player_name[20]; char team_name[20]; float batting_average; };

C Program to Copy String Using Pointer

/* Write a program using a pointer to copy one string to another string.  */ #include <stdio.h> int main(void)  {  char str1[50],str2[50];  int i,j;  char *p,*q;  printf("\n Enter First String : ");  scanf("%s",str1);  p=str1;  q=str2;  for(i=0;*(p+i)!='\0';i++)  {      *(q+i)=*(p+i);  } *(q+i)='\0';  printf("Copied String = %s",q);  return 0; }

C Program to Access Array using Pointer

/* Write a program using a pointer to read an array of integer and print elements in reverse order. */ #include <stdio.h> int main(void)  { int a[10],*p,i; p=a; for(i=0;i<10;i++) { printf("Enter Value for [%d] Position : ",i+1); scanf("%d",(p+i)); } for(i--;i>=0;i--) { printf("\n a[%d] = %d",i+1,*(p+i)); } return 0; }

C Program to Compare Two String Using Pointer

/* Write a program using a pointer to compare two strings.  */ #include <stdio.h> int main(void)  { char str1[50],str2[50]; int i,j; char *p,*q; printf("\n Enter First String : "); scanf("%s",str1); printf("\n Enter Second String : "); scanf("%s",str2); p=str1; q=str2; for(i=0;*(p+i)!='\0';i++) { if(*(p+i) != *(q+i)) { break; } } if(*(q+i)=='\0') { printf("\n Both String are Equal"); } else { printf("\n Both String are Not Equal"); } return 0; }

C Program to Change Value of Variable Using Pointer

/* Write a program to change the value of a variable using pointer.  */ #include <stdio.h> int main(void)  { int i=10,*p; p=&i; printf("\n Value of I = %d",i); *p=20; printf("\n Value of I After Changing = %d",i); return 0; }

C Program to Print Address of Variable

/* Write a program to print an address of a variable.  */ #include <stdio.h> int main(void)  { int i=10; printf("Address of I is %u",&i); return 0; }

Followers