Monday, 8 December 2014

Hard programs from the paper of Computer(5 programs)

Write program to check whether given string is palindrome or not:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
  char st[20];
  int flag=0,i,l;
  clrscr();
  printf("enter any string\n");
  gets(st);
  l=strlen(st);
  for(i=0;i<l/2;i++)
     if(st[i]!=st[l-1-i])
     {
                flag=1;
                break;
     }
  if(flag==0)
    printf("String is Palindrom");
  else
    printf("String is not palindrom\n");
getch();
}

Write program to find sum of two matrix:

#include <stdio.h>

int main()
{
   int m, n, c, d, first[10][10], second[10][10], sum[10][10];

   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &m, &n);
   printf("Enter the elements of first matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         scanf("%d", &first[c][d]);

   printf("Enter the elements of second matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
            scanf("%d", &second[c][d]);

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         sum[c][d] = first[c][d] + second[c][d];

   printf("Sum of entered matrices:-\n");

   for ( c = 0 ; c < m ; c++ )
   {
      for ( d = 0 ; d < n ; d++ )
         printf("%d\t", sum[c][d]);

      printf("\n");
   }

   return 0;
}

Write program to find prime number from given n numbers:

#include<stdio.h>

#include<conio.h>
int main()
{
 int num,n,div,p;
 printf("Enter any number: ");
 scanf("%d", &num);
 for(n=2; n<=num; n++)
 {
  for(div=2; div<n; div++)
  {
   if(n%div==0)
   {
     p=0;
     break;
   }
   p=1;
  }
  if(p)
    printf("\t%d",n);
 }
 getch();
 return 0;
}

Write program to enter the details of student through structure:

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

struct stud {
                char name[50];
                int roll_no;
                int marks[3];
                int total;
};

main()
{
                struct stud s[12];
                int i,j;
               
                printf("Enter the students details:\n");
                printf("In details enter the name,roll no,marks1,marks2,marks3\n");
               
                for(i=0;i<=2;i++)
                {
                                scanf("%s %d %d %d %d\n",&s[i].name,&s[i].roll_no,&s[i].marks[0],&s[i].marks[1],&s[i].marks[2]);
                }o 
                for(i=0;i<=2;i++)
                {
                                s[i].total=s[i].marks[0]+s[i].marks[1]+s[i].marks[2];
                }
                for(i=0;i<=2;i++)
                {
                                printf("name=%s\troll no=%d\tmarks1=%d\tmarks2=%d\tmarks3=%d\ttotal=%d\n",s[i].name,s[i].roll_no,s[i].marks[0],s[i].marks[1],s[i].marks[2],s[i].total);
                }
               
                getch();
}

 Write program to add numbers from 1 to K:

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

void main()
{
                int k,i,sum=0;
                printf("Enter the number till you want your addition:");
                scanf("%d",&k);
                for(i=0;i<=k;i++)
                {
                                sum=sum+i;
                }
                printf("The addition of numbers is %d",sum);
                getch();
}


Be connected to my blog for more information about C language

Please comment if you have any query................


No comments:

Post a Comment