Thursday, December 9, 2010

Weitage

C Programming Topic Wise Weightage

Topics Percentage Weightage Marks
Arrays 12 to 14 % 05 to 07
Structures 12 to 14 % 05 to 07
Pointers 12 to 16 % 06 to 08
Functions 10 to 12 % 04 to 06
Preprocessors 02 to 06 % 01 to 03
File handling 18 to 22 % 09 to 11
Command line arguments 02 to 06 % 01 to 03
Standard Coding Practices 10% 05
Total marks 100% 50




Download RealPlayer for FREE

Reverse of a String using Recursion

/* C Program to print Reverse of String Using Recursion */


#include

int main()
{
int num,rev;

printf("\nEnter a number :");
scanf("%d",&num);

rev=reverse(num);
printf("\nAfter reverse the no is :%d",rev);
return 0;
}

int sum=0,r;
reverse(int num)
{

if(num)
{
r=num%10;
sum=sum*10+r;
reverse(num/10);
}

else
return sum;
return sum;
}



Download RealPlayer for FREE

To Print Prime Factors of a number

/* C Program To Print Prime Factors of a number */

#include
int main()
{
int num,i=1,j,k;
printf("\nEnter a number:");
scanf("%d",&num);
while(i<=num){
k=0;
if(num%i==0){
j=1;
while(j<=i){
if(i%j==0)
k++;
j++;
}
if(k==2)
printf("\n%d is a prime factor",i);
}
i++;
}
return 0;
}


Download RealPlayer for FREE

function program to get Sum Average And SD of 5

/* function program to get Sum Average And SD of 5 */

#include
#include

int calc (float a, float b, float c, float d, float e, float *sum, float *avg,float *sd);

int main()
{
float a, b, c, d, e, sum=0.0, avg=0.0;

float sd=0.0;

printf("Enter Five Numbers:");
scanf("%f %f %f %f %f",&a,&b,&c,&d,&e);

calc (a, b, c, d, e, &sum, &avg, &sd);


printf("\nSum=%f", sum);
printf("\nAverage=%f", avg);

printf("\nStandard Deviation=%f\n", sd);


getchar();

return 0;
}

calc (float a, float b, float c, float d, float e, float *sum, float *avg, float *sd)

{
float Calc=0.0;

*sum = a+b+c+d+e;

*avg = *sum / 5.0;

Calc += ( a - *avg) * ( a - *avg);

Calc += ( b - *avg) * ( b - *avg);

Calc += ( c - *avg) * ( c - *avg);
Calc += ( d - *avg) * ( d - *avg);

Calc += ( e - *avg) * ( e - *avg);


*sd = sqrt((double)Calc/5.0);

}




Thanks,
Tushar Khoje




Download RealPlayer for FREE

C Program to Print the Fibonacci Series nad in various Options

/*C Program to print the Fibonacci series with various Options*/


#include
#include

//Function Prototype

void fibo(int);
void fiborec(int,int,int);
void main()

{
int i,num1=0,num2=1;
clrscr();

//Accept User Input

printf("Please enter the no. of terms value : ");
scanf("%d",&i);

//To Call Normal Function

printf("\nWithout Recursion\n");
printf("%5d%5d",num1,num2);
fibo(i-3);

//To Call Recursive Function

printf("\n\nUsing Recursion\n");
printf("%5d%5d",num1,num2);
fiborec(num1,num2,i-2);
getch();

}//End of main()

void fibo(int n)
{
int i,previous=1,sum=1,result=0;
for(i=0;i<=n;i++)
{
sum=previous+result;

result=previous;
previous=sum;
printf("%5d",sum);

}//End of For Loop

}//End of fibo()

void fiborec(int previous,int num2,int count)
{
int sum;

sum = previous + num2;
printf("%5d",sum);
count--;

if(count>0)//Exit Condition (Very Important in Recursion)
{
fiborec(num2,sum,count);

}
}//End of fiborec()

/*OUTPUT
--------
Please enter the no. of terms value : 12
Without Recursion

0 1 1 2 3 5 8 13 21 34 55 89

Using Recursion
0 1 1 2 3 5 8 13 21 34 55 89 */


-----------------------------------

Download RealPlayer for FREE

-----------------------------------

To Print Pascle Triangle

The C Program for it is :




#include
void main()
{
int a[10][10];
int i,j,c,n;

printf("Enter how many lines do you want");
scanf("%d",&n);

a[1][1]=1;
printf("%5d",a[1][1]);

a[2][1]=1;a[2][2]=2;a[2][3]=1;
printf("%d %d %d",a[2][1],a[2][2],a[2][3]);

for(i=3;i<=n;i++)
{

a[i][1]=1;
printf("%d",a[i][1]);
j=2;c=3;

while(j<=i)
{
a[i][j]=a[i-1][c-1]+a[i-1][c-2];
printf("%5d",a[i][j]);
c=c+1;
j=j+1;
}

a[i][j]=1;
printf("%d",a[i][j]);
}
}




thanks,
Tushar Khoje



Download RealPlayer for FREE

to reverse of the String

the Program to reverse the String is as follows..


#include
#include
main()
{
char str[50],revstr[50];
int i=0,j=0,a;
printf("Enter the string to be reversed : ");
scanf("%s",str);

a=strlen(str);

for(i=a-1;i>=0;i--)
{
revstr[j]=str[i];
j++;
}

revstr[j]='\0';

printf("Input String : %s",str);
printf("\nOutput String : %s",revstr);

getch();

}




thanks,
Tushar Khoje



Download RealPlayer for FREE