Wednesday, 4 April 2018

Pattern



    5
   54
  543
 5432
54321


int main()
{
  int i,j;
  for(i=5;i>=1;i--)
  {
    for(j=1;j<i;j++)
      printf(" ");
    for(j=5;j>=i;j--)
      printf("%d",j);
    printf("\n");
  }
  return 0;
}




     A
    ABA
   ABCBA
  ABCDCBA
 ABCDEDCBA
 
  1. #include<stdio.h>    
  2. int main(){  
  3.   int ch=65;    
  4.     int i,j,k,m;    
  5.   system("cls");  
  6.     for(i=1;i<=5;i++)    
  7.     {    
  8.         for(j=5;j>=i;j--)    
  9.             printf(" ");    
  10.         for(k=1;k<=i;k++)    
  11.             printf("%c",ch++);    
  12.             ch--;    
  13.         for(m=1;m<i;m++)    
  14.             printf("%c",--ch);    
  15.         printf("\n");    
  16.         ch=65;    
  17.     }    
  18. return 0;  
  19. }  


























Tuesday, 3 April 2018

Store Information of Student using File


Store Information of Student using File
############################################

#include <stdio.h>
int main()
{
   char name[50];
   int marks, i, num;

   printf("Enter number of students: ");
   scanf("%d", &num);

   FILE *fptr;
   fptr = (fopen("C:\\student.txt", "w"));
   if(fptr == NULL)
   {
       printf("Error!");
        }

   for(i = 0; i < num; ++i)
   {
      printf("For student%d\nEnter name: ", i+1);
      scanf("%s", name);

      printf("Enter marks: ");
      scanf("%d", &marks);

      fprintf(fptr,"\nName: %s \nMarks=%d \n", name, marks);
   }

   fclose(fptr);
  
}

Monday, 2 April 2018

Structure Program




Write a C program by using structure to display the information of Employee. It includes
name of the employee, age, salary and date of joining

===========================================


#include<stdio.h>
#include<string.h>
struct employee
{
char name[50];
int age;
int sal;
int joining;
}record;
int main()
{
record.age=14;
strcpy(record.name,"ram");
record.sal=1000;
record.joining=32;
printf("%s \n",record.name);
printf("%d \n",record.age);
printf("%d \n",record.sal);
printf("%d \n",record.joining);
return 0;
}



C program to add two integers using pointers.


#########  C program to add two integers using pointers.


#include <stdio.h>
int main()
{
   int first, second, *p, *q, sum;

   printf("Enter two integers to add\n");
   scanf("%d%d", &first, &second);

   p = &first;
   q = &second;

   sum = *p + *q;

   printf("Sum of the numbers = %d\n", sum);

   return 0;
}