Monday, 5 November 2018

LESSON 3 Factorial of a number using recursion C Programming

Factorial of a number using recursion

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f;
clrscr();
printf("Enter the limit");
scanf("%d",&n);
f=fact(n);
printf("factorial is %d",f);
getch();
}
int fact(int x)
{
int p;
if(x==0)
return(1);
else
{
p=x*fact(x-1);
}
return(p);
}

LESSON 4 Checking whether a string palindrome C Programming

Cheking whether a string palindrome

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 int n,i,flag=0,j;
 char a[32];
 clrscr();
 printf("enter the string");
 scanf("%s",a);
 n=strlen(a);
 for(i=0,j=n-1;(i<n)&&(j>0);j--,i++)
  {
     if(a[i]!=a[j])
       flag=1;
  }
     if(flag==1)
     printf("the string is not palindrom");
     else
     printf("the string is palindrome");
     getch();
}

LESSON 5 Product of two matrix C Programming

Product of two matrix

#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,p,q,i,j,k,a[20][20],b[20][20],c[20][20];
clrscr();
printf("enter the no of rows & columnsof matrix 1\n");
scanf("%d%d",&m,&n);
if(m==0||n==0)
{
printf("matrix is not possible");
}
printf("enter the array elements\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the no of rows & columnsof matrix 2\n");
scanf("%d%d",&p,&q);
if(p==0||q==0)
{
printf("matrix is not possible");
}
printf("enter the array elements\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("the  matrix 1 is \n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n\n\n");
}
printf("the  matrix 2 is \n\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n\n\n");
}
printf("\n");
if(n==p)
printf("multiplication is possible\n");
else
{
printf("multiplication is not possible");
exit(0);
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
printf("product is\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n\n\n");
}
getch();
}

LESSON 6 Details of two students and their three marks m1,m2,m3 C Programming

Details of two students and their three marks m1,m2,m3

#include<stdio.h>
#include<conio.h>
void main()
{
struct stud{
    char name[20];
    int m1;
    int m2;
    int m3;
    int m4;
    int total;
    char grade[20];
    }a[100],temp;
 int n,i,j ;
 clrscr();
 printf("enter no. of students");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
printf("enter details \nname,m1,m2,m3,m4");
    scanf("%s",a[i].name);
    scanf("%d%d%d%d",&a[i].m1,&a[i].m2,&a[i].m3,&a[i].m4);
    a[i].total=a[i].m1+a[i].m2+a[i].m3+a[i].m4;
    }
 for(i=0;i<n;i++)
 {
 for(j=0;j<n-i;j++)
 {
 if(a[j].total<a[j+1].total)
  {
  temp=a[j];
  a[j]=a[j+1];
  a[j+1]=temp;
  }
  }
  }printf("\nname\tm1\tm2\tm3\tm4\ttotal");
 for(i=0;i<n;i++)
 printf(" \n%s\t%d\t%d\t%d\t%d\t%d",a[i].name,a[i].m1,a[i].m2,a[i].m3,a[i].m4,a[i].total);
 getch();
 }

To remove odd lines from notepad++

Open the replace dialog (Ctrl + H)
Select "Regular expression"
Find what: .+\r\n(.+(\r\n|$))
Replace with:  $1
Press "Replace All"

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes