//coded by Z
#include<stdio.h>
void main()
{
int i,n,r,s,sum1,sum2;
clrscr();
printf("\nEnter a no:");
scanf("%d",&n);
r=n%2;
(r==0)?printf("\nEVEN"):printf("\t\t\tODD");
sum1=0;
sum2=0;
r=2;
s=1;
while(r&&s<=n)
{
printf("\n%d",r);
printf("\t\t\t%d",s);
sum1=sum1+r;
r=r+2;
sum2=sum2+s;
s=s+2;
}
printf("\n\nSUM1=%d",sum1);
printf("\t\t\tSUM2=%d",sum2);
getch();
}
Search This Blog
C program for calculating difference of two matrices
//coded by Z
#include<stdio.h>
void main()
{
int a[2][2],b[2][2],d[2][2],i,j;
clrscr();
printf("\nEnter first matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&a[i][j]);}
printf("\nEnter second matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&b[i][j]);}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
d[i][j]=a[i][j]-b[i][j];
printf("\nDifference of two matrices\n");
for(i=0;i<2;i++)
{ printf("\n\n ");
for(j=0;j<2;j++){
printf("%d\t",d[i][j]);}
}
getch();
}
#include<stdio.h>
void main()
{
int a[2][2],b[2][2],d[2][2],i,j;
clrscr();
printf("\nEnter first matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&a[i][j]);}
printf("\nEnter second matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&b[i][j]);}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
d[i][j]=a[i][j]-b[i][j];
printf("\nDifference of two matrices\n");
for(i=0;i<2;i++)
{ printf("\n\n ");
for(j=0;j<2;j++){
printf("%d\t",d[i][j]);}
}
getch();
}
C program for calculating sum of two matrices
//coded by Z
#include<stdio.h>
void main()
{
int a[2][2],b[2][2],s[2][2],i,j;
clrscr();
printf("\nEnter first matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&a[i][j]);}
printf("\nEnter second matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&b[i][j]);}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
s[i][j]=a[i][j]+b[i][j];
printf("\nSum of two matrices\n");
for(i=0;i<2;i++)
{ printf("\n\n ");
for(j=0;j<2;j++){
printf("%d\t",s[i][j]);}
}
getch();
}
#include<stdio.h>
void main()
{
int a[2][2],b[2][2],s[2][2],i,j;
clrscr();
printf("\nEnter first matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&a[i][j]);}
printf("\nEnter second matrix\t\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++){
scanf("%d",&b[i][j]);}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
s[i][j]=a[i][j]+b[i][j];
printf("\nSum of two matrices\n");
for(i=0;i<2;i++)
{ printf("\n\n ");
for(j=0;j<2;j++){
printf("%d\t",s[i][j]);}
}
getch();
}
C program for implementing pointers
//coded by Z
#include<stdio.h>
void main()
{
int v=0;
int *pv;
clrscr();
pv=&v;
printf("\n\n\n\tv=%d",v);
printf("\n\n\n\tpv=%d",*pv);
getch();
}
#include<stdio.h>
void main()
{
int v=0;
int *pv;
clrscr();
pv=&v;
printf("\n\n\n\tv=%d",v);
printf("\n\n\n\tpv=%d",*pv);
getch();
}
C program for generating student details using structure
//coded by Z
#include<stdio.h>
struct student
{
char name[20];
int age,mark1,mark2,total;
float percent;
};
void main()
{
struct student stud;
clrscr();
printf("\n\n\nEnter name=");
scanf("%s",stud.name);
printf("\nEnter age=");
scanf("%d",&stud.age);
printf("\nEnter mark1=");
scanf("%d",&stud.mark1);
printf("\nEnter mark2=");
scanf("%d",&stud.mark2);
stud.total=stud.mark1+stud.mark2;
stud.percent=stud.total*100.0/200;
printf("________________________________________________________________________________");
printf("\t\t\t\t------");
printf("\n\t\t\t\tREPORT");
printf("\n\t\t\t\t------");
printf("\n\n\n\n\t\t\t1.NAME=%s\n",stud.name);
printf("\n\t\t\t2.AGE=%d\n",stud.age);
printf("\n\t\t\t3.TOTAL MARKS=%d\n",stud.total);
printf("\n\t\t\t4.PERCENTAGE=%.2f\n",stud.percent);
printf("________________________________________________________________________________");
printf("\n\t\t\t\t\t\t\t\t\t ZS");
getch();
}
#include<stdio.h>
struct student
{
char name[20];
int age,mark1,mark2,total;
float percent;
};
void main()
{
struct student stud;
clrscr();
printf("\n\n\nEnter name=");
scanf("%s",stud.name);
printf("\nEnter age=");
scanf("%d",&stud.age);
printf("\nEnter mark1=");
scanf("%d",&stud.mark1);
printf("\nEnter mark2=");
scanf("%d",&stud.mark2);
stud.total=stud.mark1+stud.mark2;
stud.percent=stud.total*100.0/200;
printf("________________________________________________________________________________");
printf("\t\t\t\t------");
printf("\n\t\t\t\tREPORT");
printf("\n\t\t\t\t------");
printf("\n\n\n\n\t\t\t1.NAME=%s\n",stud.name);
printf("\n\t\t\t2.AGE=%d\n",stud.age);
printf("\n\t\t\t3.TOTAL MARKS=%d\n",stud.total);
printf("\n\t\t\t4.PERCENTAGE=%.2f\n",stud.percent);
printf("________________________________________________________________________________");
printf("\n\t\t\t\t\t\t\t\t\t ZS");
getch();
}
C program for checking two strings are equal or not
//coded by Z
#include<stdio.h>
#include<string.h>
void main()
{
int c;
char s1[20],s2[20];
clrscr();
printf("type string\n");
gets(s1);
printf("type another string\n");
gets(s2);
c=strcmp(s1,s2);
if(c==0)
{
printf("EQUAL");
}
else
{
printf("NOT EQUAL");
}
getch();
}
#include<stdio.h>
#include<string.h>
void main()
{
int c;
char s1[20],s2[20];
clrscr();
printf("type string\n");
gets(s1);
printf("type another string\n");
gets(s2);
c=strcmp(s1,s2);
if(c==0)
{
printf("EQUAL");
}
else
{
printf("NOT EQUAL");
}
getch();
}
C program for linear searching and sorting
//coded by Z
#include<stdio.h>
void main()
{
int z,b,l,u[20],flag=0;
clrscr();
printf("\nHow many no:s to be entered=\n");
scanf("%d",&l);
printf("\nEnter %d no:s\n\n",l);
for(z=0;z<l;z++)
{
scanf("%d",&u[z]);
}
printf("\nEnter number to be searched\n");
scanf("%d",&b);
for(z=0;z<=l;z++)
if(u[z]==b)
{
flag=1;
printf("\nthe searched no: %d is present at %d\n",b,z+1);
}
if (flag==0)
{
printf("\nsearched no:%d is not present ",b);
}
getch();
}
#include<stdio.h>
void main()
{
int z,b,l,u[20],flag=0;
clrscr();
printf("\nHow many no:s to be entered=\n");
scanf("%d",&l);
printf("\nEnter %d no:s\n\n",l);
for(z=0;z<l;z++)
{
scanf("%d",&u[z]);
}
printf("\nEnter number to be searched\n");
scanf("%d",&b);
for(z=0;z<=l;z++)
if(u[z]==b)
{
flag=1;
printf("\nthe searched no: %d is present at %d\n",b,z+1);
}
if (flag==0)
{
printf("\nsearched no:%d is not present ",b);
}
getch();
}
C program for generating an asterisk pattern
//coded by Z
#include<stdio.h>
void main()
{
int i,j,n;
clrscr();
printf("\n enter value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=i;j++)
{printf("* ");
}
}
getch();
}
#include<stdio.h>
void main()
{
int i,j,n;
clrscr();
printf("\n enter value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=i;j++)
{printf("* ");
}
}
getch();
}
C program for checking a string is palindrome or not
//coded by Z
#include<stdio.h>
void main()
{
char st[25];
int i,j,flag=1;
clrscr();
printf("\nEnter a word\n\n");
gets(st);
for(i=0;st[i]!='\0';i++)
for(j=1,i=0;st[j]!=st[i]&&i<j;i++,j++)
{
flag=0;
break;
}
if(flag==1)
printf("\nThe word is a palindrome");
else
printf("\nThe word is not a palindrome");
getch();
}
#include<stdio.h>
void main()
{
char st[25];
int i,j,flag=1;
clrscr();
printf("\nEnter a word\n\n");
gets(st);
for(i=0;st[i]!='\0';i++)
for(j=1,i=0;st[j]!=st[i]&&i<j;i++,j++)
{
flag=0;
break;
}
if(flag==1)
printf("\nThe word is a palindrome");
else
printf("\nThe word is not a palindrome");
getch();
}
C program for bubble sorting an array
//coded by Z
#include<stdio.h>
void main()
{
int z,b,n,temp,a[20];
clrscr();
printf("\n\n\nEnter the limit\n\n\t");
scanf("\t%d",&n);
for(z=0;z<n;z++)
scanf("\t%d",&a[z]);
for(z=0;z<=n-1;z++)
{
for(b=0;b<=n-2;b++)
if(a[b]>a[b++])
{
temp=a[b];
a[b]=a[b+1];
a[b++]=temp;
}
}
printf("\n\nthe bubble sorted array\n");
for(z=0;z<=n-1;z++)
printf("\n\t%d",a[z]);
getch();
}
#include<stdio.h>
void main()
{
int z,b,n,temp,a[20];
clrscr();
printf("\n\n\nEnter the limit\n\n\t");
scanf("\t%d",&n);
for(z=0;z<n;z++)
scanf("\t%d",&a[z]);
for(z=0;z<=n-1;z++)
{
for(b=0;b<=n-2;b++)
if(a[b]>a[b++])
{
temp=a[b];
a[b]=a[b+1];
a[b++]=temp;
}
}
printf("\n\nthe bubble sorted array\n");
for(z=0;z<=n-1;z++)
printf("\n\t%d",a[z]);
getch();
}
C program for calculating sum of 2 numbers using user defined function
//coded by Z
#include<stdio.h>
int sum(int a,int b);
void main()
{
int x,y;
clrscr();
printf("enter two no:s \n");
scanf("%d %d",&x,&y);
printf("sum=%d",sum(x,y));
getch();
}
int sum(int a,int b)
{
int s;
s= a+b;
return (s);
}
#include<stdio.h>
int sum(int a,int b);
void main()
{
int x,y;
clrscr();
printf("enter two no:s \n");
scanf("%d %d",&x,&y);
printf("sum=%d",sum(x,y));
getch();
}
int sum(int a,int b)
{
int s;
s= a+b;
return (s);
}
C program for matrix multiplication
//coded by Z
#include<stdio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],r1,c1,r2,c2,i,j,k,z;
clrscr();
printf("\nEnter the order of 1st matrix=\n");
scanf("%d %d",&r1,&c1);
printf("\nEnter the order of 2nd matrix=\n");
scanf("%d %d",&r2,&c2);
if(c1!=r2)
printf("\n\nMultiplication is not possible");
else
printf("\n\nEnter the elements of 1st matrix\n");
{
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
printf("\n\nEnter the elements of 2nd matrix\n");
for(j=0;j<r2;j++)
for(k=0;k<c2;k++)
scanf("%d",&b[j][k]);
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<r2;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
printf("\nThe first matrix is\n");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c1;j++)
printf("\t%d\t",a[i][j]);
for(z=0;z<1;z++)
{printf("\n[\t\t\t\t]");}
}
printf("\n\nThe second matrix is\n");
for(i=0;i<r2;i++)
{
printf("\n");
for(j=0;j<c2;j++)
printf("\t%d\t",b[i][j]);
for(z=0;z<1;z++)
{ printf("\n[\t\t\t\t]");}
}
printf("\nThe resultant matrix is\n");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c2;j++)
printf("\t%d\t",c[i][j]);
for(z=0;z<1;z++)
{ printf("\n[\t\t\t\t]");}
}
getch();
}
#include<stdio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],r1,c1,r2,c2,i,j,k,z;
clrscr();
printf("\nEnter the order of 1st matrix=\n");
scanf("%d %d",&r1,&c1);
printf("\nEnter the order of 2nd matrix=\n");
scanf("%d %d",&r2,&c2);
if(c1!=r2)
printf("\n\nMultiplication is not possible");
else
printf("\n\nEnter the elements of 1st matrix\n");
{
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
printf("\n\nEnter the elements of 2nd matrix\n");
for(j=0;j<r2;j++)
for(k=0;k<c2;k++)
scanf("%d",&b[j][k]);
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<r2;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
printf("\nThe first matrix is\n");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c1;j++)
printf("\t%d\t",a[i][j]);
for(z=0;z<1;z++)
{printf("\n[\t\t\t\t]");}
}
printf("\n\nThe second matrix is\n");
for(i=0;i<r2;i++)
{
printf("\n");
for(j=0;j<c2;j++)
printf("\t%d\t",b[i][j]);
for(z=0;z<1;z++)
{ printf("\n[\t\t\t\t]");}
}
printf("\nThe resultant matrix is\n");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c2;j++)
printf("\t%d\t",c[i][j]);
for(z=0;z<1;z++)
{ printf("\n[\t\t\t\t]");}
}
getch();
}
C progam for finding factorial of a number using function
//coded by Z
#include<stdio.h>
int fact(int n);
void main()
{
int n,f;
clrscr();
printf("\n Enter the value of n=");
scanf("%d",&n);
f=fact(n);
printf("\nfactorial of %d is %d",n,f);
getch();
}
int fact(int n)
{
int f;
if(n==0)
return(1);
else
f=n*fact(n-1);
return(f);
}
#include<stdio.h>
int fact(int n);
void main()
{
int n,f;
clrscr();
printf("\n Enter the value of n=");
scanf("%d",&n);
f=fact(n);
printf("\nfactorial of %d is %d",n,f);
getch();
}
int fact(int n)
{
int f;
if(n==0)
return(1);
else
f=n*fact(n-1);
return(f);
}
Basic C program
//coded by Z
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\n\nHello!");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\n\nHello!");
getch();
}
Subscribe to:
Comments (Atom)