you know what guys,
In my college we use laptops for 24×7,we write /taught various programmes.
These are the programmes that I have learned (not remembere),taught as a part of c language.
We thankful to Dennis Ritche ....!Isn't it guys....?
I would like to share all the programmes that i have learned , copied, downloaded with you .
These might helpful at certain time either to you or to me.
1)Printing the Armstrong number :
/* print the armstrong number*/
/* Author D.Shiva:B082533*/
#include <stdio.h>
int main(void)
{
int i, x, n, j; /*intializing of variables*/
printf( "\n Enter a number: " );/*take input from excutor*/
scanf( "%d", &n );
x = n;
i = 0;
while( x > 0 )
{
j =x%10;
}
break;
case 2:
printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
i =i+j * j * j ;
x=x/10;
}
if(n== i)
printf( "\n%d is an Armstrong number\n", n);
else
printf("\n%d is an not Armstrong number\n",n);
}
------------------------------------------------------------------------------------------------------------------------------------
2)Printing of armstrong number in between the rage.
/* Author D.Shiva:B082533*/
#include<stdio.h>
int main(void)
{
int x,n,am,y,z;
printf("Enter range :\n");
scanf("%d",&z);
for(n=0;n<=z;n++)
{
am=n;
int sum=0;
while(am>0)
{
y=am%10;
am=am/10;
x=y*y*y;
sum=sum+x;
}
if(sum==n)
printf("%d\n",n);
}
}
------------------------------------------------------------------------------------------------------------------------------------
3)Use of for loop :
(Calculation of simple interest for 3 sets of p, n and r )
/* Author D.Shiva:B082533*/
#include<stdio.h>
main ( )
{
int p, n, count ;
float r, si ;
for ( count = 1 ; count <= 3 ; count = count + 1 )
{
printf ( "Enter values of p, n, and r " ) ;
scanf ( "%d %d %f", &p, &n, &r ) ;
si = p * n * r / 100 ;
printf ( "Simple Interest = Rs.%f\n", si ) ;
}
}
------------------------------------------------------------------------------------------------------------------------------------
4)Use of while loop :
( Calculation of simple interest for 3 sets of p, n and r )
/* Author D.Shiva:B082533*/
#include<stdio.h>
/* Calculation of simple interest for 3 sets of p, n and r */
main( )
{
int p, n, count ;
float r, si ;
count = 1 ;
while ( count <= 3 )
{
printf ( "\nEnter values of p, n and r " ) ;
scanf ( "%d %d %f", &p, &n, &r ) ;
si = p * n * r / 100 ;
printf ( "Simple interest = Rs. %f", si ) ;
count = count + 1 ;
}
}
------------------------------------------------------------------------------------------------------------------------------------
5) Binary number :
#include<stdio.h>
int main(void)
{
int x,y,arr[10],i=0,len;
printf("Enter the number:\n");
scanf("%d", &x);
while(x>0)
{
y = x%2;
x = x/2;
arr[i++]=y;
}
i =i-1;
while(i>=0)
{
printf("%d",arr[i--]);
}
}
------------------------------------------------------------------------------------------------------------------------------------
6)Binary number
#include<stdio.h>
int main(void)
{
int x,y,arr[10],i=0,len;
printf("Enter the number:\n");
scanf("%d", &x);
while(x>0)
{
arr[i++] = x%2;
x /= 2;
}
len = i;
i =1;
while(i>=0)
{
printf("%d",arr[i]);
i--;
}
printf("\n");
}
------------------------------------------------------------------------------------------------------------------------------------
7)Know factorial of number n :
# include<stdio.h>
int factorial(unsigned int number)
{
if(number <= 1)
return 1;
else
return number * factorial(number - 1);
}
void main()
{
int x;
printf("\nEnter which number you want to know factorial\n");
scanf("%d",&x);
factorial(x);
printf("\nfactorial of %d is %d\n\n",x,factorial(x));
}
------------------------------------------------------------------------------------------------------------------------------------
8)Iteration (prime,even number) :
#include<stdio.h>
#include<time.h>
main()
{
clock_t c1,c2; c1=clock();
int m, n, l, x;
printf("Enter the number ");
scanf("%d", &m);
if(m%2==0)
{
printf("This is Even number\n");
}
else
{
if(m%2==1 && m%5!=0)
{
if(m%5==1 || m%5==4)
l=1;
else
l=-1;
n=m-l;
x=fib(n,m);
if(x==0)
printf("%d\tThis is prime\n", m);
else
printf("%d\tThis isn't prime\n", m);
}
}
int a, b, x1, x2, x3;
printf("Enter the valuses of a and b:\n");
scanf("%d%d", &a,&b);
x1= addmod(a, b, m);
x2= submod(a, b, m);
x3= multimod(a, b, m);
c2=clock();
printf("time : %lf\n",(double)(c2-c1)/(double)CLOCKS_PER_SEC);
}
fib(int n,int m, int f1, int f2,int f, int count )
{
count=0;
while(f<=n)
{
++count;
f=addmode(f1,f2,m);
f2=f1;
f1=f;
}
}
------------------------------------------------------------------------------------------------------------------------------------
9)Astrology
#include<stdio.h>
main()
{
int x,n,m,o,p,q,s;
printf("");
printf("\n\nSELECT WHICH ASTROLOGY YOU WANT TO KNOW \n\n");
printf("\n");
printf("1)Ur face astrology\n2)Marriage method in future astrology\n3)Dr.Love Game, Ur Love story a moive type lo untundho chudham\n4)In which month u like to marri. I will tell who marry u\n5)Ne jevitamlo edhi mundhu dorukuthundho chudham\n6)Prapacham lo Ninnu yevaru over ga love chestaro chudham\n\n\n");
printf("Select above one of the astrology and Enter your number in between 1 to 6:\n\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("@
\nwell come to face astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any number. I will tell ur face astrology\n\n");
printf("Enter ur selected no:\n\n",n);
scanf("%d",&n);
switch(n)
{
case 1:
printf("smilling face\n\n");
break;
case 2:
printf("watse face\n\n");
break;
case 3:
printf("tension face\n\n");
break;
case 4:
printf("Innocent face\n\n");
break;
case 5:
printf("Terror face\n\n");
break;
case 6:
printf("Lovable face\n\n");
break;
case 7:
printf("Romantic face\n\n");@
break;
case 8:
@");
printf("\n\nSELECT WHICH ASTROLOGY YOU WANT TO KNOW \n\n");
printf("\n");
printf("1)Ur face astrology\n2)Marriage method in future astrology\n3)Dr.Love Game, Ur Love story a moive type lo untundho chudham\n4)In which month u like to marri. I will tell who marry u\n5)Ne jevitamlo edhi mundhu dorukuthundho chudham\n6)Prapacham lo Ninnu yevaru over ga love chestaro chudham\n\n\n");
printf("Select above one of the astrology and Enter your number in between 1 to 6:\n\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("\n well come to face astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any number. I will tell ur face astrology\n\n");
printf("Enter ur selected no:\n\n",n);
scanf("%d",&n);
switch(n)
{
case 1:
printf("smilling face\n\n");
break;
case 2:
printf("watse face\n\n");
break;
case 3:
printf("tension face\n\n");
break;
case 4:
printf("Innocent face\n\n");
break;
case 5:
printf("Terror face\n\n");
break;
case 6:
printf("Lovable face\n\n");
break;
case 7:
printf("Romantic face\n\n");
break;
case 8:
printf("crual face\n\n");
break;
case 9:
printf("decent face\n\n");
break;
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
@");
printf("\n\nSELECT WHICH ASTROLOGY YOU WANT TO KNOW \n\n");
printf("@
\n");
printf("1)Ur face astrology\n2)Marriage method in future astrology\n3)Dr.Love Game, Ur Love story a moive type lo untundho chudham\n4)In which month u like to marri. I will tell who marry u\n5)Ne jevitamlo edhi mundhu dorukuthundho chudham\n6)Prapacham lo Ninnu yevaru over ga love chestaro chudham\n\n\n");
printf("Select above one of the astrology and Enter your number in between 1 to 6:\n\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("\n well come to face astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any number. I will tell ur face astrology\n\n");
printf("Enter ur selected no:\n\n",n);
scanf("%d",&n);
switch(n)
{
case 1:
printf("smilling face\n\n");
break;
case 2:
printf("watse face\n\n");
break;
case 3:
printf("tension face\n\n");
break;
case 4:
printf("Innocent face\n\n");
break;
case 5:
printf("Terror face\n\n");
break;
case 6:
printf("Lovable face\n\n");
break;
case 7:
printf("Romantic face\n\n");
break;
case 8:
printf("crual face\n\n");
break;
case 9:
printf("decent face\n\n");
break;
case 10:
printf("joker face\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
switch(m)
case 10:
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");@@
printf("Enter ur selected no\n\n");
scanf("%d",&m);
printf("joker face\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
switch(m)
printf("crual face\n\n");
break;
case 9:
printf("decent face\n\n");
break;
case 10:
printf("joker face\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
switch(m)
{
case 1:
printf("arrange marriage\n\n");
break;
case 2:
printf("Quickly\n\n");
break;
case 3:
printf("love mrg\n\n");
break;
case 4:
printf("love+arranged\n\n");
break;
case 5:
printf("Marry ur school or college friend\n\n");
break;
case 6:
printf("U will love some 1 but marri some one\n\n");
break;
case 7:
printf("U will go against ur parents nd marri\n\n");
break;
case 8:
printf("Parents choice\n\n");
break;
case 9:
printf("u will marri ur ralatives\n\n");
break;
case 10:
printf("Ur choice\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 3:
printf("\nWel come to ur love story type astrology\n \n1 2 3 4 5 6 7 8 9 10 select any one number.I will tell you ur love story which movie type\n\n");
printf("Enter ur select no\n\n");
scanf("%d",&o);
switch(o)
{
case 1:
printf("kushi\n\n");
break;
case 2:
printf("orange\n\n");
break;
case 3:
printf("ye maya chesave \n\n");
break;
case 4:
printf("Desamudhuru\n\n");
break;
case 5:
printf("murari\n\n");
break;
case 6:
printf("arya\n\n");
break;
case 7:
printf("parugu\n\n");
break;
case 8:
printf("idiot\n\n");
break;
case 9:
printf("darling\n\n");
break;
case 10:
printf("nuvvustanante nen vadhantana\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n");
}
break;
case 4:
printf("@
\nwel come month marriage astrology\n\nselect one month number like jan=1, feb=2, mar=3....Dec=12. I will tell you who will marri you\n@
\n");
printf("Enter ur selected no\n\n");
scanf("%d",&p);
switch(p)
{
case 1:
printf("Neighbour\n\n");
break;
case 2:
printf("Classmet\n\n");
break;
case 3:
printf("Stranger\n\n");
break;
case 4:
printf("whom u love\n\n");
break;
case 5:
printf("Ineterfriend\n\n");
break;
case 6:
printf("Relative\n\n");
break;
case 7:
printf("Friend\n\n");
break;
case 8:
printf("collegue\n\n");
break;
case 9:
printf("papular 1\n\n");
break;
case 10:
printf("other cast\n\n");
case 11:
printf("beautiful or handsome person\n\n");
case 12:
printf("begger\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 5:
printf("\n wel come to which one u will get first in ur life astrology\n\nselect any number from 1 to 10. I will tell you which one you get first in ur life\n\n");
printf("Enter ur selected no\n\n");
scanf("%d",&q);
switch(q)
{
case 1:
printf("money\n\n");
break;
case 2:
printf("life parter\n\n");
break;
case 3:
printf("job\n\n");
break;
case 4:
printf("girl friend\n\n");
break;
case 5:
printf("enjoy life\n\n");
break;
case 6:
printf("happy life\n\n");
break;
case 7:
printf("higher education\n\n");
break;
case 8:
printf("true love\n\n");
break;
case 9:
printf("respect\n\n");
break;
case 10:
printf("marrieage life\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 6:
printf("\n Wel come to whom u love most astrology\n\nselect no from 1 to 10. I will tell you who love u most in the world\n\n");
printf("enter ur selected no\n\n");
scanf("%d",&s);
switch(s)
{
case 1:
printf("me\n\n");
break;
case 2:
printf("sister\n\n");
break;
case 3:
printf("mother\n\n");
break;
case 4:
printf("lover\n\n");
break;
case 5:
printf("god\n\n");
break;
case 6:
printf("life parter\n\n");
break;
case 7:
printf("friend\n\n");
break;
case 8:
printf("father\n\n");
break;
case 9:
printf("brother\n\n");
break;
case 10:
printf("one of the relative\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
}
------------------------------------------------------------------------------------------------------------------------------------
10)Write in order :
#include<stdio.h>
void CountDown(int n)
{
if(n>0)
{
printf("%d", n);
CountDown(n-1);
}
}
main()
{
int n=5;
CountDown(5);
printf("\n");
}
------------------------------------------------------------------------------------------------------------------------------------
11)Program to store the first n fibonacci numbers in an array :
#include<stdio.h>
main()
{
int n,fibo[100],a=1,b=1,c,d;
printf("\nEnter any integer:");
scanf("%d",&n);
fibo[0]=a;
fibo[1]=b;
for(d=2;d<=n;d++)
{
c=a+b;
fibo[d]=c;
a=b;
b=c;
}
for(d=0;d<n;d++)
printf("%d\t",fibo[d]);
printf("\n");
}
------------------------------------------------------------------------------------------------------------------------------------
12)Program to find Determinant of a Matrix
/*Program to find Determinant of a Matrix*/
#include<stdio.h>
#define LIMIT 10
void main()
{
int i,j,order,chckdiognal();
float deter();
float a[LIMIT][LIMIT],value;
printf("Enter order of determent :");
scanf("%d",&order);
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("Enter (%d,%d) element of the determent :",i+1,j+1);
scanf("%f",&a[i][j]);
}
}
if(chckdiognal(a,order)==0)
value=0;
else
value=deter(a,order);
printf("Determinent Value :%f",value);
}
float deter(float a[][LIMIT],int forder)
{
int i,j,k;
float mult;
float deter=1;
for(i=0;i<forder;i++)
{
for(j=0;j<forder;j++)
{
mult=a[j][i]/a[i][i];
for(k=0;k<forder;k++)
{
if(i==j) break;
a[j][k]=a[j][k]-a[i][k]*mult;
}
}
}
for(i=0;i<forder;i++)
{
deter=deter*a[i][i];
}
return(deter);
}
int chckdiognal(float array[][LIMIT],int forder)
{
int i,j,k;
float nonzero;
for(i=0;i<forder;i++)
{
if(array[i][i]==0)
{
for(j=0;j<forder;j++)
{
if(array[i][j]!=0)
{
k=j;
break;
}
if(j==(forder)) //forder-1
return(0);
}
for(j=0;j<forder;j++)
{
array[j][i]=array[j][i]-array[j][k];
}
}
}
return(1);
}
------------------------------------------------------------------------------------------------------------------------------------
13.Program to Multiply Two Matrices
/*Program to Multiply Two Matrices*/
#include<stdio.h>
#define MAXROWS 30
#define MAXCOLS 30
void readinput(int a[][MAXCOLS],int m,int n);
void computeproduct(int a[][MAXCOLS],int b[][MAXCOLS],int c[][MAXCOLS],int m,int n,int p);
void writeoutput(int c[][MAXCOLS],int m,int p);
int z=0;
void main()
{
int nrows,ncols,mrows,mcols;
int a[MAXROWS][MAXCOLS],b[MAXROWS][MAXCOLS],c[MAXROWS][MAXCOLS];
printf("How many rows in the first matrix? ");
scanf("%d",&nrows);
printf("How many cols in the first matrix? ");
scanf("%d",&ncols);
printf("How many rows in the second matrix? ");
scanf("%d",&mrows);
printf("How many cols in the second matrix? ");
scanf("%d",&mcols);
if (ncols != mrows)
{
printf("The product of these matrices is not defined.");
exit(0);
}
printf("First table:");
readinput(a,nrows,ncols);
printf("Second table:");
readinput(b,mrows,mcols);
computeproduct(a,b,c,nrows,ncols,mcols);
printf("Product of the matrices is:");
writeoutput(c,nrows,mcols);
}
void readinput(int a[][MAXCOLS],int m,int n)
{
int row,col;
for (row=0;row<m;row++)
{
printf("Enter data for row no.1=%d,row+1");
for (col=0;col<n;col++)
scanf("%d",&a[row][col]);
}
z=z+1;
printf("Table %d",z);
for (row=0;row<m;row++)
{
for (col=0;col<n;col++)
printf("%d%c",a[row][col],' ');
printf("");
}
return;
}
void computeproduct(int a[][MAXCOLS],int b[][MAXCOLS],int c[][MAXCOLS],int m,int n,int p)
{
int i,j,k,sum=0;
for (i=0;i<m;i++)
{
for (j=0;j<p;j++)
{
for (k=0;k<n;k++)
sum=sum+(a[i][k]*b[k][j]);
c[i][j]=sum;
sum=0;
}
}
return;
}
void writeoutput(int c[][MAXCOLS],int m,int p)
{
int row,col;
for (row=0;row<m;row++)
{
for (col=0;col<p;col++)
printf("%6d",c[row][col]);
printf("");
}
return;
}
------------------------------------------------------------------------------------------------------------------------------------
14.Perfect number
#include<stdio.h>
main()
{
int n,i,s;
printf("Ent er any number:");
scanf("%d",&n);
i=1;
s=0;
while(i<n)
{
if(n%i==0)
s=s+i;
i++;
}
if(s==n)
printf("%d is aperfect number",n);
else
printf("%d is not aperfect number",n);
}
------------------------------------------------------------------------------------------------------------------------------------
15.Pyramid
/* 1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1 */
/*this thing we have to print */
#include<stdio.h>
main()
{
int i=1,j,c,b;
printf ("enter range:");
scanf("%d",&j);
while(j>=i)
{
printf("\n");
for(c=1;c<=j;c++)
printf("%d",c);
for(c=j;c>=1;c--)
printf("%d",c);
j--;
}
}
------------------------------------------------------------------------------------------------------------------------------------
16.Pyramid 2
#include<stdio.h>
main()
{
int j,i=1,b=0,c;
printf("enter your range;");
scanf("%d",&j);
while(j>=i)
{
printf("\n");
for(c=1;c<=b;c++)
printf(" ");
for(c=1;c<=j;c++)
printf("%d",c);
for(c=j;c>=1;c--)
printf("%d",c);
b++;
j--;
}
printf("\n\n\n");
}
------------------------------------------------------------------------------------------------------------------------------------
17.Structure
#include<stdio.h>
#include<string.h>
main()
{
struct class
{
char stud_name[20];
char stud_id[8];
char stud_branch[20];
};
struct class d[15];
int i;
for(i=0;i<15;i++)
{
printf("Enter student%d name:",i+1);
scanf("%s", d[i].stud_name);
printf("Enter %s ID no:", d[i].stud_name);
scanf("%s", d[i].stud_id);
printf("Enter %s's Branch:", d[i].stud_name);
scanf("%s", d[i].stud_branch);
}
}
------------------------------------------------------------------------------------------------------------------------------------
18.Structure 1
#include<stdio.h>
#include<string.h>
main()
{
struct Employee
{
char emp_id[6];
char emp_name[20];
char gender[6];
int emp_sal;
char email_add[50];
};
struct Employee d[10];
int i;
for(i=0;i<10;i++)
{
printf("Enter the Employee%d name:",i+1);
scanf("%s", d[i].emp_name);
printf("Enter the %s Id:", d[i].emp_name);
scanf("%s", d[i].emp_id);
printf("Enter the gender of %s", d[i].emp_name);
scanf("%s", d[i].gender);
printf("Enter the salary of %s", d[i].emp_name);
scanf("%d", &d[i].emp_sal);
printf("Enter the email address of %s", d[i].emp_name);
scanf("%s", d[i].email_add);
}
}
------------------------------------------------------------------------------------------------------------------------------------
19.Continue and break statements :
break :
#include<stdio.h>
main( )
{
int num, i ;
printf ( "Enter a number " ) ;
scanf ( "%d", &num ) ;
i=2;
while ( i <= num - 1 )
{
if ( num % i == 0 )
{
printf ( "Not a prime number" ) ;
break ;
}
i++;
if ( i == num )
printf ( "Prime number" ) ;
}
}
break1
#include<stdio.h>
main( )
{
int i = 1 , j = 1 ;
while ( i++ <= 100 )
{
while ( j++ <= 200 )
{
if ( j == 150 )
break ;
else
printf ( "%d %d\n", i, j ) ;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------
Continue statement :
#include<stdio.h>
main( )
{
int i, j ;
for ( i = 1 ; i <= 2 ; i++ )
{
for ( j = 1 ; j <= 2 ; j++ )
{
if ( i == j )
continue ;
printf ( "\n%d %d\n", i, j ) ;
}
}
}
/*out put is
1 2
2 1
*/
------------------------------------------------------------------------------------------------------------------------------------
21.do-while loop :
#include<stdio.h>
main( )
{
do
{
printf ( "Hello there \n") ;
} while ( 4 < 1 ) ;
}
------------------------------------------------------------------------------------------------------------------------------------
22.Swapping :
#include<stdio.h>
main()
{
int a[10],b[10],i;
printf("enter the value of a");
for(i=0;i<10;i++);
{
scanf("%d",&a[i]);
}
printf("enter the value of b");
for(i=0;i<10;i++);
{
scanf("%d",&b[i]);
}
}
------------------------------------------------------------------------------------------------------------------------------------
23.Sum up to n numbers :
#include<stdio.h>
main()
{
int i,n,s;
printf("enter any number");
scanf("%d",&n);
for(i=o;i<=n;i++)
{
printf("enter the natural number of %d");
s=s+i;
printf("enter the sum is %d",s);
}
}
------------------------------------------------------------------------------------------------------------------------------------
24.Matrix transpose
#include<stdio.h>
main()
{
int a[3][3];
clrscr();
transpose(a);
}
inti,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("matrix formed");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf("transpose is:\n");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
}---------------------------------------------------------------------------------------------------------------------------------- 25.Adding two matrices :
#include<stdio.h>
main()
{
int a[3],b[3],c[3]=0,i,j,k;
clrscr();
printf("enter matrix A value");
for(i=0;i<=3;i++)
{
scanf("%d",&a[i]);
}
printf("enter matrx B value");
for(i=;i<3;i++)
{
scanf("%d",&b[i]);
}
for(j=0;j<=3;j++)
a[k]=a[i]+b[j];
}
printf("resultant matrix");
for(k=0;k<3;k++)
{
printf("%d",c[k]);
}
------------------------------------------------------------------------------------------------------------------------------------
26.String copy
#include<stdio.h>
main()
{
char str1="NEWZELAND";
char str2="INDIA";
printf("befor using strcpy");
printf("%s",str1);
strcpy(str1,str2);
printf("after using strcpy");
printf("%s",str1);
}
------------------------------------------------------------------------------------------------------------------------------------
27.String concatenation :
#include<stdio.h>
main()
{
char str1[10]="cevis";
char str2[]="kiwis";
strcat(str1,str2);
printf("str1");
}
------------------------------------------------------------------------------------------------------------------------------------
28.the reverse of given number :
#include<stdio.h>
main()
{
int i,r;
clrscr();
printf("enter the value for i");
scanf("%d",&i);
do
{
r=i%10;
r=(r*10)+r;
i=i/10;
}
while(i>10);
printf("the reverse of given number is%d",r);
}
------------------------------------------------------------------------------------------------------------------------------------
29.Read string :
#include<stdio.h>
main()
{
int a[10],i,name;
printf("enter the value of a");
scanf("%s", &name);
for(i=0;i<=1;i++)
printf("%s",name);
}
------------------------------------------------------------------------------------------------------------------------------------
30.Prime number :
#include<stdio.h>
main()
{
int i,m, n,count=0;
printf("enter m value");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
for(i=1;i<=n;i++)
{
("n%i==0")
(count==2)
printf("%d n");
}
}
}
------------------------------------------------------------------------------------------------------------------------------------
31.Perfect number :
#include<stdio.h>
main()
{
int i,n,sum=0;
clrscr();
printf("enter a value for n");
scanf("%d",&n);
for(i=1;i<n;i++)
{
sum=sum+i;
}
if(n==sum)
printf("given number is perfect number");
else
printf("given number is not a perfect number");
}
------------------------------------------------------------------------------------------------------------------------------------
32.Odd number :
#include<stdio.h>
main()
{
int i,n;
clrscr();
printf("enter value for n");
scanf("%d",&n);
for(i=1;i<=n;i++);
{
if(i%2==1);
}
printf("\t%d",i);
}
------------------------------------------------------------------------------------------------------------------------------------
33.Even number :
#include<stdio.h>
main()
{
int i,n;
clrscr();
printf("enter value for n");
scanf("%d",&n);
for(i=1;i<=n;i++);
{
if(i%2==1);
}
printf("\t%d",i);
}
------------------------------------------------------------------------------------------------------------------------------------
34.Random number :
#include<stdlib.h>
#include<stdio.h>
main()
{
int a[100],i;
clrscr();
i=0;
while(i<=100)
{
a[i]=a[100];
i++;
}
i=0;
printf(" randum numbers are:");
while(i<=100)
printf("%d",a[i]);
i++;
}
------------------------------------------------------------------------------------------------------------------------------------
35.Armstrong -checking :
#include<stdio.h>
main()
{
int i,n,amg=0;
printf("enter n value");
scanf("%d",&n);
for(i=n;i>0;i=i/10)
{
amg=amg+(i%10)*(i%10)*(i%10);
}
if(amg==n)
printf("given number is armstrong");
else
printf("given number is not a amstrong");
}
------------------------------------------------------------------------------------------------------------------------------------
36.Three numbers average :
#include<stdio.h>
main()
{
avg();
}
avg()
{
int a,b,c, avg;
clrscr();
printf("enter a,b,c values");
scanf("%d%d%d",&a,&b,&c);
avg=(a+b+c)/3;
printf("%d",avg);
}
------------------------------------------------------------------------------------------------------------------------------------
37.Factorial - another :
#include<stdio.h>
main()
{
int f=1,n,i=1;
printf("enter n values");
scanf("%d",&n);
do
{
f=f*i;
i++;
}
while(i<=n);
printf("factorial is %d",f);
}
-----------------------------------------------------------------------------------------------------------------------------------
38.given number is palindrome or not?
#include<stdio.h>
main()
{
int i,n,rev=0,num;
printf("enter n value");
scanf("%d",&n);
num=n;
for(i=n;i>0;i=i%10)
{
rev=((rev*10)+(i=i--));
}
if(rev==num)
printf("the given number is palindrome");
else
{
printf("the given number is not a palindrome");
}
}
-----------------------------------------------------------------------------------------------------------------------------------
39.Give number is perfect number or not?
#include<stdio.h>
main()
{
int i,n,sum=0;
printf("enter a value");
scanf("%d",&n);
for(i=1;i<n;i++);
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%dis not a perfect number",i);
}
-----------------------------------------------------------------------------------------------------------------------------------
40.Given number is prime or not?
#include<stdio.h>
main()
{
int i,n,count=0;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
count++;
}
if(count==2)
printf("given number is prime");
else
printf("given number is not prime");
}
-----------------------------------------------------------------------------------------------------------------------------------
41.Matrix multiplication :
#include<stdio.h>
void main()
{
int m1[10][10],i,j,k,m2[10][10],add[10][10],mult[10][10],r1,c1,r2,c2;
printf("Enter number of rows and columns of first matrix MAX 10\n");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of second matrix MAX 10\n");
scanf("%d%d",&r2,&c2);
if(r2==c1)
{
printf("Enter rows and columns of First matrix \n");
printf("Row wise\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("You have entered the first matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[i][j]);
printf("\n");
}
printf("Enter rows and columns of Second matrix \n");
printf("Again row wise\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the second matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
if(r1==r2&&c1==c2)
{
printf("Now we add both the above matrix \n");
printf("The result of the addition is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[i][j]=m1[i][j]+m2[i][j];
printf("%d\t",add[i][j]);
}
printf("\n");
}
}
else
{
printf("Addition cannot be done as rows or columns are not equal\n");
}
printf("Now we multiply both the above matrix \n");
printf("The result of the multiplication is as follows:\n");
/*a11xA11+a12xA21+a13xA31 a11xA12+a12xA22+a13xA32 a11xA13+a12xA23+a13xA33*/
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
else
{
printf("Matrix multiplication cannot be done");
}
}
-----------------------------------------------------------------------------------------------------------------------------------
42.Base power
#include<stdio.h>
#include<math.h>
main()
{
int base,i=0,n;
printf("\nEnter the n value:");
scanf("%d",&n);
printf("\nEnter the base value:");
scanf("%d",&base);
while(i<=n)
{
printf("%2d^%d=%.0f\n",base,i,pow(base,i));
i=i+1;
}
}
-----------------------------------------------------------------------------------------------------------------------------------
43.Bubble sort
#include<stdio.h>
int main()
{
int size;
printf("No. of elements: ");
scanf("%d",&size);
int data[size],i;
for(i=0;i<size;i++)
scanf("%d",data+i);
printf("\nArray elements: ");
for(i=0;i<size;i++)
printf("%d ",*(data+i));
int j,temp;
for(i=0;i<size-1;i++)
{
for(j=i+1;j<size;j++)
{
if(data[j] < data[i])
{
temp = *(data+i);
*(data+i)= data[j];
data[j]=temp;
}
}
}
printf("\nArray elements after sorting: ");
for(i=0;i<size;i++)
printf("%d ",data[i]);
printf("\n");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------
44.Convertion of temparature from Celcious to Fahrenheit
#include<stdio.h>
#define upper 300
#define lower 0
#define step 20
main()
{
int cel;
printf("\nConvertion of temparature from Celcious to Fahrenheit\n");
for(cel=lower;cel<=upper;cel=cel+step)
{
printf("%3d=%7.2f\n",cel,(((9.0/5.0)*cel)+32));
}
}
-----------------------------------------------------------------------------------------------------------------------------------
45.Member variables for the complex structure
#include<stdio.h>
typedef struct
{
float real; //////Member variables for the complex structure//////
float imag;
}complex;
complex add(complex a, complex b);
void input(complex *);
void display(complex);
int main()
{
complex a,b,c;
input(&a);
input(&b);
c=add(a,b);
display(a);
display(b);
printf("\nAddition of above two complex numbers");
display(c);
return 0;
}
void display(complex a)
{
printf("%.1f+i(%.1f)\n",a.real,a.imag);
}
void input(complex *p)
{
printf("Enter real and imaginar values for the complex number: ");
scanf("%f%f",&(p -> real),&(p -> imag));
}
complex add(complex a, complex b)
{
complex temp;
temp.real=a.real+b.real;
temp.imag=a.imag+b.imag;
return temp;
}
-----------------------------------------------------------------------------------------------------------------------------------
46.number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
In my college we use laptops for 24×7,we write /taught various programmes.
These are the programmes that I have learned (not remembere),taught as a part of c language.
We thankful to Dennis Ritche ....!Isn't it guys....?
I would like to share all the programmes that i have learned , copied, downloaded with you .
These might helpful at certain time either to you or to me.
1)Printing the Armstrong number :
/* print the armstrong number*/
/* Author D.Shiva:B082533*/
#include <stdio.h>
int main(void)
{
int i, x, n, j; /*intializing of variables*/
printf( "\n Enter a number: " );/*take input from excutor*/
scanf( "%d", &n );
x = n;
i = 0;
while( x > 0 )
{
j =x%10;
}
break;
case 2:
printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
i =i+j * j * j ;
x=x/10;
}
if(n== i)
printf( "\n%d is an Armstrong number\n", n);
else
printf("\n%d is an not Armstrong number\n",n);
}
------------------------------------------------------------------------------------------------------------------------------------
2)Printing of armstrong number in between the rage.
/* Author D.Shiva:B082533*/
#include<stdio.h>
int main(void)
{
int x,n,am,y,z;
printf("Enter range :\n");
scanf("%d",&z);
for(n=0;n<=z;n++)
{
am=n;
int sum=0;
while(am>0)
{
y=am%10;
am=am/10;
x=y*y*y;
sum=sum+x;
}
if(sum==n)
printf("%d\n",n);
}
}
------------------------------------------------------------------------------------------------------------------------------------
3)Use of for loop :
(Calculation of simple interest for 3 sets of p, n and r )
/* Author D.Shiva:B082533*/
#include<stdio.h>
main ( )
{
int p, n, count ;
float r, si ;
for ( count = 1 ; count <= 3 ; count = count + 1 )
{
printf ( "Enter values of p, n, and r " ) ;
scanf ( "%d %d %f", &p, &n, &r ) ;
si = p * n * r / 100 ;
printf ( "Simple Interest = Rs.%f\n", si ) ;
}
}
------------------------------------------------------------------------------------------------------------------------------------
4)Use of while loop :
( Calculation of simple interest for 3 sets of p, n and r )
/* Author D.Shiva:B082533*/
#include<stdio.h>
/* Calculation of simple interest for 3 sets of p, n and r */
main( )
{
int p, n, count ;
float r, si ;
count = 1 ;
while ( count <= 3 )
{
printf ( "\nEnter values of p, n and r " ) ;
scanf ( "%d %d %f", &p, &n, &r ) ;
si = p * n * r / 100 ;
printf ( "Simple interest = Rs. %f", si ) ;
count = count + 1 ;
}
}
------------------------------------------------------------------------------------------------------------------------------------
5) Binary number :
#include<stdio.h>
int main(void)
{
int x,y,arr[10],i=0,len;
printf("Enter the number:\n");
scanf("%d", &x);
while(x>0)
{
y = x%2;
x = x/2;
arr[i++]=y;
}
i =i-1;
while(i>=0)
{
printf("%d",arr[i--]);
}
}
------------------------------------------------------------------------------------------------------------------------------------
6)Binary number
#include<stdio.h>
int main(void)
{
int x,y,arr[10],i=0,len;
printf("Enter the number:\n");
scanf("%d", &x);
while(x>0)
{
arr[i++] = x%2;
x /= 2;
}
len = i;
i =1;
while(i>=0)
{
printf("%d",arr[i]);
i--;
}
printf("\n");
}
------------------------------------------------------------------------------------------------------------------------------------
7)Know factorial of number n :
# include<stdio.h>
int factorial(unsigned int number)
{
if(number <= 1)
return 1;
else
return number * factorial(number - 1);
}
void main()
{
int x;
printf("\nEnter which number you want to know factorial\n");
scanf("%d",&x);
factorial(x);
printf("\nfactorial of %d is %d\n\n",x,factorial(x));
}
------------------------------------------------------------------------------------------------------------------------------------
8)Iteration (prime,even number) :
#include<stdio.h>
#include<time.h>
main()
{
clock_t c1,c2; c1=clock();
int m, n, l, x;
printf("Enter the number ");
scanf("%d", &m);
if(m%2==0)
{
printf("This is Even number\n");
}
else
{
if(m%2==1 && m%5!=0)
{
if(m%5==1 || m%5==4)
l=1;
else
l=-1;
n=m-l;
x=fib(n,m);
if(x==0)
printf("%d\tThis is prime\n", m);
else
printf("%d\tThis isn't prime\n", m);
}
}
int a, b, x1, x2, x3;
printf("Enter the valuses of a and b:\n");
scanf("%d%d", &a,&b);
x1= addmod(a, b, m);
x2= submod(a, b, m);
x3= multimod(a, b, m);
c2=clock();
printf("time : %lf\n",(double)(c2-c1)/(double)CLOCKS_PER_SEC);
}
fib(int n,int m, int f1, int f2,int f, int count )
{
count=0;
while(f<=n)
{
++count;
f=addmode(f1,f2,m);
f2=f1;
f1=f;
}
}
------------------------------------------------------------------------------------------------------------------------------------
9)Astrology
#include<stdio.h>
main()
{
int x,n,m,o,p,q,s;
printf("");
printf("\n\nSELECT WHICH ASTROLOGY YOU WANT TO KNOW \n\n");
printf("\n");
printf("1)Ur face astrology\n2)Marriage method in future astrology\n3)Dr.Love Game, Ur Love story a moive type lo untundho chudham\n4)In which month u like to marri. I will tell who marry u\n5)Ne jevitamlo edhi mundhu dorukuthundho chudham\n6)Prapacham lo Ninnu yevaru over ga love chestaro chudham\n\n\n");
printf("Select above one of the astrology and Enter your number in between 1 to 6:\n\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("@
\nwell come to face astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any number. I will tell ur face astrology\n\n");
printf("Enter ur selected no:\n\n",n);
scanf("%d",&n);
switch(n)
{
case 1:
printf("smilling face\n\n");
break;
case 2:
printf("watse face\n\n");
break;
case 3:
printf("tension face\n\n");
break;
case 4:
printf("Innocent face\n\n");
break;
case 5:
printf("Terror face\n\n");
break;
case 6:
printf("Lovable face\n\n");
break;
case 7:
printf("Romantic face\n\n");@
break;
case 8:
@");
printf("\n\nSELECT WHICH ASTROLOGY YOU WANT TO KNOW \n\n");
printf("\n");
printf("1)Ur face astrology\n2)Marriage method in future astrology\n3)Dr.Love Game, Ur Love story a moive type lo untundho chudham\n4)In which month u like to marri. I will tell who marry u\n5)Ne jevitamlo edhi mundhu dorukuthundho chudham\n6)Prapacham lo Ninnu yevaru over ga love chestaro chudham\n\n\n");
printf("Select above one of the astrology and Enter your number in between 1 to 6:\n\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("\n well come to face astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any number. I will tell ur face astrology\n\n");
printf("Enter ur selected no:\n\n",n);
scanf("%d",&n);
switch(n)
{
case 1:
printf("smilling face\n\n");
break;
case 2:
printf("watse face\n\n");
break;
case 3:
printf("tension face\n\n");
break;
case 4:
printf("Innocent face\n\n");
break;
case 5:
printf("Terror face\n\n");
break;
case 6:
printf("Lovable face\n\n");
break;
case 7:
printf("Romantic face\n\n");
break;
case 8:
printf("crual face\n\n");
break;
case 9:
printf("decent face\n\n");
break;
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
@");
printf("\n\nSELECT WHICH ASTROLOGY YOU WANT TO KNOW \n\n");
printf("@
\n");
printf("1)Ur face astrology\n2)Marriage method in future astrology\n3)Dr.Love Game, Ur Love story a moive type lo untundho chudham\n4)In which month u like to marri. I will tell who marry u\n5)Ne jevitamlo edhi mundhu dorukuthundho chudham\n6)Prapacham lo Ninnu yevaru over ga love chestaro chudham\n\n\n");
printf("Select above one of the astrology and Enter your number in between 1 to 6:\n\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("\n well come to face astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any number. I will tell ur face astrology\n\n");
printf("Enter ur selected no:\n\n",n);
scanf("%d",&n);
switch(n)
{
case 1:
printf("smilling face\n\n");
break;
case 2:
printf("watse face\n\n");
break;
case 3:
printf("tension face\n\n");
break;
case 4:
printf("Innocent face\n\n");
break;
case 5:
printf("Terror face\n\n");
break;
case 6:
printf("Lovable face\n\n");
break;
case 7:
printf("Romantic face\n\n");
break;
case 8:
printf("crual face\n\n");
break;
case 9:
printf("decent face\n\n");
break;
case 10:
printf("joker face\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
switch(m)
case 10:
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");@@
printf("Enter ur selected no\n\n");
scanf("%d",&m);
printf("joker face\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
switch(m)
printf("crual face\n\n");
break;
case 9:
printf("decent face\n\n");
break;
case 10:
printf("joker face\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 2:
printf("\n
@\nWel come to marriage method astrology\n\n 1 2 3 4 5 6 7 8 9 10 select any one number. I will tell Ur marriage method in future\n");
printf("Enter ur selected no\n\n");
scanf("%d",&m);
switch(m)
{
case 1:
printf("arrange marriage\n\n");
break;
case 2:
printf("Quickly\n\n");
break;
case 3:
printf("love mrg\n\n");
break;
case 4:
printf("love+arranged\n\n");
break;
case 5:
printf("Marry ur school or college friend\n\n");
break;
case 6:
printf("U will love some 1 but marri some one\n\n");
break;
case 7:
printf("U will go against ur parents nd marri\n\n");
break;
case 8:
printf("Parents choice\n\n");
break;
case 9:
printf("u will marri ur ralatives\n\n");
break;
case 10:
printf("Ur choice\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 3:
printf("\nWel come to ur love story type astrology\n \n1 2 3 4 5 6 7 8 9 10 select any one number.I will tell you ur love story which movie type\n\n");
printf("Enter ur select no\n\n");
scanf("%d",&o);
switch(o)
{
case 1:
printf("kushi\n\n");
break;
case 2:
printf("orange\n\n");
break;
case 3:
printf("ye maya chesave \n\n");
break;
case 4:
printf("Desamudhuru\n\n");
break;
case 5:
printf("murari\n\n");
break;
case 6:
printf("arya\n\n");
break;
case 7:
printf("parugu\n\n");
break;
case 8:
printf("idiot\n\n");
break;
case 9:
printf("darling\n\n");
break;
case 10:
printf("nuvvustanante nen vadhantana\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n");
}
break;
case 4:
printf("@
\nwel come month marriage astrology\n\nselect one month number like jan=1, feb=2, mar=3....Dec=12. I will tell you who will marri you\n@
\n");
printf("Enter ur selected no\n\n");
scanf("%d",&p);
switch(p)
{
case 1:
printf("Neighbour\n\n");
break;
case 2:
printf("Classmet\n\n");
break;
case 3:
printf("Stranger\n\n");
break;
case 4:
printf("whom u love\n\n");
break;
case 5:
printf("Ineterfriend\n\n");
break;
case 6:
printf("Relative\n\n");
break;
case 7:
printf("Friend\n\n");
break;
case 8:
printf("collegue\n\n");
break;
case 9:
printf("papular 1\n\n");
break;
case 10:
printf("other cast\n\n");
case 11:
printf("beautiful or handsome person\n\n");
case 12:
printf("begger\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 5:
printf("\n wel come to which one u will get first in ur life astrology\n\nselect any number from 1 to 10. I will tell you which one you get first in ur life\n\n");
printf("Enter ur selected no\n\n");
scanf("%d",&q);
switch(q)
{
case 1:
printf("money\n\n");
break;
case 2:
printf("life parter\n\n");
break;
case 3:
printf("job\n\n");
break;
case 4:
printf("girl friend\n\n");
break;
case 5:
printf("enjoy life\n\n");
break;
case 6:
printf("happy life\n\n");
break;
case 7:
printf("higher education\n\n");
break;
case 8:
printf("true love\n\n");
break;
case 9:
printf("respect\n\n");
break;
case 10:
printf("marrieage life\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
case 6:
printf("\n Wel come to whom u love most astrology\n\nselect no from 1 to 10. I will tell you who love u most in the world\n\n");
printf("enter ur selected no\n\n");
scanf("%d",&s);
switch(s)
{
case 1:
printf("me\n\n");
break;
case 2:
printf("sister\n\n");
break;
case 3:
printf("mother\n\n");
break;
case 4:
printf("lover\n\n");
break;
case 5:
printf("god\n\n");
break;
case 6:
printf("life parter\n\n");
break;
case 7:
printf("friend\n\n");
break;
case 8:
printf("father\n\n");
break;
case 9:
printf("brother\n\n");
break;
case 10:
printf("one of the relative\n\n");
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
break;
default:
printf("Ur Selected incorrect number. Plz select again in between 1 to 6 only\n\n");
}
}
------------------------------------------------------------------------------------------------------------------------------------
10)Write in order :
#include<stdio.h>
void CountDown(int n)
{
if(n>0)
{
printf("%d", n);
CountDown(n-1);
}
}
main()
{
int n=5;
CountDown(5);
printf("\n");
}
------------------------------------------------------------------------------------------------------------------------------------
11)Program to store the first n fibonacci numbers in an array :
#include<stdio.h>
main()
{
int n,fibo[100],a=1,b=1,c,d;
printf("\nEnter any integer:");
scanf("%d",&n);
fibo[0]=a;
fibo[1]=b;
for(d=2;d<=n;d++)
{
c=a+b;
fibo[d]=c;
a=b;
b=c;
}
for(d=0;d<n;d++)
printf("%d\t",fibo[d]);
printf("\n");
}
------------------------------------------------------------------------------------------------------------------------------------
12)Program to find Determinant of a Matrix
/*Program to find Determinant of a Matrix*/
#include<stdio.h>
#define LIMIT 10
void main()
{
int i,j,order,chckdiognal();
float deter();
float a[LIMIT][LIMIT],value;
printf("Enter order of determent :");
scanf("%d",&order);
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("Enter (%d,%d) element of the determent :",i+1,j+1);
scanf("%f",&a[i][j]);
}
}
if(chckdiognal(a,order)==0)
value=0;
else
value=deter(a,order);
printf("Determinent Value :%f",value);
}
float deter(float a[][LIMIT],int forder)
{
int i,j,k;
float mult;
float deter=1;
for(i=0;i<forder;i++)
{
for(j=0;j<forder;j++)
{
mult=a[j][i]/a[i][i];
for(k=0;k<forder;k++)
{
if(i==j) break;
a[j][k]=a[j][k]-a[i][k]*mult;
}
}
}
for(i=0;i<forder;i++)
{
deter=deter*a[i][i];
}
return(deter);
}
int chckdiognal(float array[][LIMIT],int forder)
{
int i,j,k;
float nonzero;
for(i=0;i<forder;i++)
{
if(array[i][i]==0)
{
for(j=0;j<forder;j++)
{
if(array[i][j]!=0)
{
k=j;
break;
}
if(j==(forder)) //forder-1
return(0);
}
for(j=0;j<forder;j++)
{
array[j][i]=array[j][i]-array[j][k];
}
}
}
return(1);
}
------------------------------------------------------------------------------------------------------------------------------------
13.Program to Multiply Two Matrices
/*Program to Multiply Two Matrices*/
#include<stdio.h>
#define MAXROWS 30
#define MAXCOLS 30
void readinput(int a[][MAXCOLS],int m,int n);
void computeproduct(int a[][MAXCOLS],int b[][MAXCOLS],int c[][MAXCOLS],int m,int n,int p);
void writeoutput(int c[][MAXCOLS],int m,int p);
int z=0;
void main()
{
int nrows,ncols,mrows,mcols;
int a[MAXROWS][MAXCOLS],b[MAXROWS][MAXCOLS],c[MAXROWS][MAXCOLS];
printf("How many rows in the first matrix? ");
scanf("%d",&nrows);
printf("How many cols in the first matrix? ");
scanf("%d",&ncols);
printf("How many rows in the second matrix? ");
scanf("%d",&mrows);
printf("How many cols in the second matrix? ");
scanf("%d",&mcols);
if (ncols != mrows)
{
printf("The product of these matrices is not defined.");
exit(0);
}
printf("First table:");
readinput(a,nrows,ncols);
printf("Second table:");
readinput(b,mrows,mcols);
computeproduct(a,b,c,nrows,ncols,mcols);
printf("Product of the matrices is:");
writeoutput(c,nrows,mcols);
}
void readinput(int a[][MAXCOLS],int m,int n)
{
int row,col;
for (row=0;row<m;row++)
{
printf("Enter data for row no.1=%d,row+1");
for (col=0;col<n;col++)
scanf("%d",&a[row][col]);
}
z=z+1;
printf("Table %d",z);
for (row=0;row<m;row++)
{
for (col=0;col<n;col++)
printf("%d%c",a[row][col],' ');
printf("");
}
return;
}
void computeproduct(int a[][MAXCOLS],int b[][MAXCOLS],int c[][MAXCOLS],int m,int n,int p)
{
int i,j,k,sum=0;
for (i=0;i<m;i++)
{
for (j=0;j<p;j++)
{
for (k=0;k<n;k++)
sum=sum+(a[i][k]*b[k][j]);
c[i][j]=sum;
sum=0;
}
}
return;
}
void writeoutput(int c[][MAXCOLS],int m,int p)
{
int row,col;
for (row=0;row<m;row++)
{
for (col=0;col<p;col++)
printf("%6d",c[row][col]);
printf("");
}
return;
}
------------------------------------------------------------------------------------------------------------------------------------
14.Perfect number
#include<stdio.h>
main()
{
int n,i,s;
printf("Ent er any number:");
scanf("%d",&n);
i=1;
s=0;
while(i<n)
{
if(n%i==0)
s=s+i;
i++;
}
if(s==n)
printf("%d is aperfect number",n);
else
printf("%d is not aperfect number",n);
}
------------------------------------------------------------------------------------------------------------------------------------
15.Pyramid
/* 1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1 */
/*this thing we have to print */
#include<stdio.h>
main()
{
int i=1,j,c,b;
printf ("enter range:");
scanf("%d",&j);
while(j>=i)
{
printf("\n");
for(c=1;c<=j;c++)
printf("%d",c);
for(c=j;c>=1;c--)
printf("%d",c);
j--;
}
}
------------------------------------------------------------------------------------------------------------------------------------
16.Pyramid 2
#include<stdio.h>
main()
{
int j,i=1,b=0,c;
printf("enter your range;");
scanf("%d",&j);
while(j>=i)
{
printf("\n");
for(c=1;c<=b;c++)
printf(" ");
for(c=1;c<=j;c++)
printf("%d",c);
for(c=j;c>=1;c--)
printf("%d",c);
b++;
j--;
}
printf("\n\n\n");
}
------------------------------------------------------------------------------------------------------------------------------------
17.Structure
#include<stdio.h>
#include<string.h>
main()
{
struct class
{
char stud_name[20];
char stud_id[8];
char stud_branch[20];
};
struct class d[15];
int i;
for(i=0;i<15;i++)
{
printf("Enter student%d name:",i+1);
scanf("%s", d[i].stud_name);
printf("Enter %s ID no:", d[i].stud_name);
scanf("%s", d[i].stud_id);
printf("Enter %s's Branch:", d[i].stud_name);
scanf("%s", d[i].stud_branch);
}
}
------------------------------------------------------------------------------------------------------------------------------------
18.Structure 1
#include<stdio.h>
#include<string.h>
main()
{
struct Employee
{
char emp_id[6];
char emp_name[20];
char gender[6];
int emp_sal;
char email_add[50];
};
struct Employee d[10];
int i;
for(i=0;i<10;i++)
{
printf("Enter the Employee%d name:",i+1);
scanf("%s", d[i].emp_name);
printf("Enter the %s Id:", d[i].emp_name);
scanf("%s", d[i].emp_id);
printf("Enter the gender of %s", d[i].emp_name);
scanf("%s", d[i].gender);
printf("Enter the salary of %s", d[i].emp_name);
scanf("%d", &d[i].emp_sal);
printf("Enter the email address of %s", d[i].emp_name);
scanf("%s", d[i].email_add);
}
}
------------------------------------------------------------------------------------------------------------------------------------
19.Continue and break statements :
break :
#include<stdio.h>
main( )
{
int num, i ;
printf ( "Enter a number " ) ;
scanf ( "%d", &num ) ;
i=2;
while ( i <= num - 1 )
{
if ( num % i == 0 )
{
printf ( "Not a prime number" ) ;
break ;
}
i++;
if ( i == num )
printf ( "Prime number" ) ;
}
}
break1
#include<stdio.h>
main( )
{
int i = 1 , j = 1 ;
while ( i++ <= 100 )
{
while ( j++ <= 200 )
{
if ( j == 150 )
break ;
else
printf ( "%d %d\n", i, j ) ;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------
Continue statement :
#include<stdio.h>
main( )
{
int i, j ;
for ( i = 1 ; i <= 2 ; i++ )
{
for ( j = 1 ; j <= 2 ; j++ )
{
if ( i == j )
continue ;
printf ( "\n%d %d\n", i, j ) ;
}
}
}
/*out put is
1 2
2 1
*/
------------------------------------------------------------------------------------------------------------------------------------
21.do-while loop :
#include<stdio.h>
main( )
{
do
{
printf ( "Hello there \n") ;
} while ( 4 < 1 ) ;
}
------------------------------------------------------------------------------------------------------------------------------------
22.Swapping :
#include<stdio.h>
main()
{
int a[10],b[10],i;
printf("enter the value of a");
for(i=0;i<10;i++);
{
scanf("%d",&a[i]);
}
printf("enter the value of b");
for(i=0;i<10;i++);
{
scanf("%d",&b[i]);
}
}
------------------------------------------------------------------------------------------------------------------------------------
23.Sum up to n numbers :
#include<stdio.h>
main()
{
int i,n,s;
printf("enter any number");
scanf("%d",&n);
for(i=o;i<=n;i++)
{
printf("enter the natural number of %d");
s=s+i;
printf("enter the sum is %d",s);
}
}
------------------------------------------------------------------------------------------------------------------------------------
24.Matrix transpose
#include<stdio.h>
main()
{
int a[3][3];
clrscr();
transpose(a);
}
inti,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("matrix formed");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf("transpose is:\n");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
}---------------------------------------------------------------------------------------------------------------------------------- 25.Adding two matrices :
#include<stdio.h>
main()
{
int a[3],b[3],c[3]=0,i,j,k;
clrscr();
printf("enter matrix A value");
for(i=0;i<=3;i++)
{
scanf("%d",&a[i]);
}
printf("enter matrx B value");
for(i=;i<3;i++)
{
scanf("%d",&b[i]);
}
for(j=0;j<=3;j++)
a[k]=a[i]+b[j];
}
printf("resultant matrix");
for(k=0;k<3;k++)
{
printf("%d",c[k]);
}
------------------------------------------------------------------------------------------------------------------------------------
26.String copy
#include<stdio.h>
main()
{
char str1="NEWZELAND";
char str2="INDIA";
printf("befor using strcpy");
printf("%s",str1);
strcpy(str1,str2);
printf("after using strcpy");
printf("%s",str1);
}
------------------------------------------------------------------------------------------------------------------------------------
27.String concatenation :
#include<stdio.h>
main()
{
char str1[10]="cevis";
char str2[]="kiwis";
strcat(str1,str2);
printf("str1");
}
------------------------------------------------------------------------------------------------------------------------------------
28.the reverse of given number :
#include<stdio.h>
main()
{
int i,r;
clrscr();
printf("enter the value for i");
scanf("%d",&i);
do
{
r=i%10;
r=(r*10)+r;
i=i/10;
}
while(i>10);
printf("the reverse of given number is%d",r);
}
------------------------------------------------------------------------------------------------------------------------------------
29.Read string :
#include<stdio.h>
main()
{
int a[10],i,name;
printf("enter the value of a");
scanf("%s", &name);
for(i=0;i<=1;i++)
printf("%s",name);
}
------------------------------------------------------------------------------------------------------------------------------------
30.Prime number :
#include<stdio.h>
main()
{
int i,m, n,count=0;
printf("enter m value");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
for(i=1;i<=n;i++)
{
("n%i==0")
(count==2)
printf("%d n");
}
}
}
------------------------------------------------------------------------------------------------------------------------------------
31.Perfect number :
#include<stdio.h>
main()
{
int i,n,sum=0;
clrscr();
printf("enter a value for n");
scanf("%d",&n);
for(i=1;i<n;i++)
{
sum=sum+i;
}
if(n==sum)
printf("given number is perfect number");
else
printf("given number is not a perfect number");
}
------------------------------------------------------------------------------------------------------------------------------------
32.Odd number :
#include<stdio.h>
main()
{
int i,n;
clrscr();
printf("enter value for n");
scanf("%d",&n);
for(i=1;i<=n;i++);
{
if(i%2==1);
}
printf("\t%d",i);
}
------------------------------------------------------------------------------------------------------------------------------------
33.Even number :
#include<stdio.h>
main()
{
int i,n;
clrscr();
printf("enter value for n");
scanf("%d",&n);
for(i=1;i<=n;i++);
{
if(i%2==1);
}
printf("\t%d",i);
}
------------------------------------------------------------------------------------------------------------------------------------
34.Random number :
#include<stdlib.h>
#include<stdio.h>
main()
{
int a[100],i;
clrscr();
i=0;
while(i<=100)
{
a[i]=a[100];
i++;
}
i=0;
printf(" randum numbers are:");
while(i<=100)
printf("%d",a[i]);
i++;
}
------------------------------------------------------------------------------------------------------------------------------------
35.Armstrong -checking :
#include<stdio.h>
main()
{
int i,n,amg=0;
printf("enter n value");
scanf("%d",&n);
for(i=n;i>0;i=i/10)
{
amg=amg+(i%10)*(i%10)*(i%10);
}
if(amg==n)
printf("given number is armstrong");
else
printf("given number is not a amstrong");
}
------------------------------------------------------------------------------------------------------------------------------------
36.Three numbers average :
#include<stdio.h>
main()
{
avg();
}
avg()
{
int a,b,c, avg;
clrscr();
printf("enter a,b,c values");
scanf("%d%d%d",&a,&b,&c);
avg=(a+b+c)/3;
printf("%d",avg);
}
------------------------------------------------------------------------------------------------------------------------------------
37.Factorial - another :
#include<stdio.h>
main()
{
int f=1,n,i=1;
printf("enter n values");
scanf("%d",&n);
do
{
f=f*i;
i++;
}
while(i<=n);
printf("factorial is %d",f);
}
-----------------------------------------------------------------------------------------------------------------------------------
38.given number is palindrome or not?
#include<stdio.h>
main()
{
int i,n,rev=0,num;
printf("enter n value");
scanf("%d",&n);
num=n;
for(i=n;i>0;i=i%10)
{
rev=((rev*10)+(i=i--));
}
if(rev==num)
printf("the given number is palindrome");
else
{
printf("the given number is not a palindrome");
}
}
-----------------------------------------------------------------------------------------------------------------------------------
39.Give number is perfect number or not?
#include<stdio.h>
main()
{
int i,n,sum=0;
printf("enter a value");
scanf("%d",&n);
for(i=1;i<n;i++);
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%dis not a perfect number",i);
}
-----------------------------------------------------------------------------------------------------------------------------------
40.Given number is prime or not?
#include<stdio.h>
main()
{
int i,n,count=0;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
count++;
}
if(count==2)
printf("given number is prime");
else
printf("given number is not prime");
}
-----------------------------------------------------------------------------------------------------------------------------------
41.Matrix multiplication :
#include<stdio.h>
void main()
{
int m1[10][10],i,j,k,m2[10][10],add[10][10],mult[10][10],r1,c1,r2,c2;
printf("Enter number of rows and columns of first matrix MAX 10\n");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of second matrix MAX 10\n");
scanf("%d%d",&r2,&c2);
if(r2==c1)
{
printf("Enter rows and columns of First matrix \n");
printf("Row wise\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("You have entered the first matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[i][j]);
printf("\n");
}
printf("Enter rows and columns of Second matrix \n");
printf("Again row wise\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the second matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
if(r1==r2&&c1==c2)
{
printf("Now we add both the above matrix \n");
printf("The result of the addition is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[i][j]=m1[i][j]+m2[i][j];
printf("%d\t",add[i][j]);
}
printf("\n");
}
}
else
{
printf("Addition cannot be done as rows or columns are not equal\n");
}
printf("Now we multiply both the above matrix \n");
printf("The result of the multiplication is as follows:\n");
/*a11xA11+a12xA21+a13xA31 a11xA12+a12xA22+a13xA32 a11xA13+a12xA23+a13xA33*/
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
else
{
printf("Matrix multiplication cannot be done");
}
}
-----------------------------------------------------------------------------------------------------------------------------------
42.Base power
#include<stdio.h>
#include<math.h>
main()
{
int base,i=0,n;
printf("\nEnter the n value:");
scanf("%d",&n);
printf("\nEnter the base value:");
scanf("%d",&base);
while(i<=n)
{
printf("%2d^%d=%.0f\n",base,i,pow(base,i));
i=i+1;
}
}
-----------------------------------------------------------------------------------------------------------------------------------
43.Bubble sort
#include<stdio.h>
int main()
{
int size;
printf("No. of elements: ");
scanf("%d",&size);
int data[size],i;
for(i=0;i<size;i++)
scanf("%d",data+i);
printf("\nArray elements: ");
for(i=0;i<size;i++)
printf("%d ",*(data+i));
int j,temp;
for(i=0;i<size-1;i++)
{
for(j=i+1;j<size;j++)
{
if(data[j] < data[i])
{
temp = *(data+i);
*(data+i)= data[j];
data[j]=temp;
}
}
}
printf("\nArray elements after sorting: ");
for(i=0;i<size;i++)
printf("%d ",data[i]);
printf("\n");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------
44.Convertion of temparature from Celcious to Fahrenheit
#include<stdio.h>
#define upper 300
#define lower 0
#define step 20
main()
{
int cel;
printf("\nConvertion of temparature from Celcious to Fahrenheit\n");
for(cel=lower;cel<=upper;cel=cel+step)
{
printf("%3d=%7.2f\n",cel,(((9.0/5.0)*cel)+32));
}
}
-----------------------------------------------------------------------------------------------------------------------------------
45.Member variables for the complex structure
#include<stdio.h>
typedef struct
{
float real; //////Member variables for the complex structure//////
float imag;
}complex;
complex add(complex a, complex b);
void input(complex *);
void display(complex);
int main()
{
complex a,b,c;
input(&a);
input(&b);
c=add(a,b);
display(a);
display(b);
printf("\nAddition of above two complex numbers");
display(c);
return 0;
}
void display(complex a)
{
printf("%.1f+i(%.1f)\n",a.real,a.imag);
}
void input(complex *p)
{
printf("Enter real and imaginar values for the complex number: ");
scanf("%f%f",&(p -> real),&(p -> imag));
}
complex add(complex a, complex b)
{
complex temp;
temp.real=a.real+b.real;
temp.imag=a.imag+b.imag;
return temp;
}
-----------------------------------------------------------------------------------------------------------------------------------
46.number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
number
------------------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment