Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: C+ program
Description: C+ programming for computational technique assigent

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


ASSIGNMENT 8
1
...
Y is X + 10 if X is between
10 and 30
...
Otherwise Y is X − 2
...
h>
#include ...
10printf("2
...
otherwise\n");
printf("4
...
A student is awarded Ex grade if he gets more than 90 marks
...
Similarly range for B, C, D and P are 70-79, 60-69, 50-59, and
35-49 respectively
...
Write a
program, which reads marks of a student and prints his grade
...
h>
#include ...
80printf("2
...
60printf("4
...
35printf("6
...
exit\n");
printf("your choice?\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter marks of the student");
scanf("%d",&x);
printf("Marks=%d",x);
printf("Grade is A\n");
break;
case 2:
printf("\nEnter marks of the student");
scanf("%d",&x);
printf("Marks=%d",x);
printf("Grade is B\n");
break;
case 3:
printf("\nEnter marks of the student");
scanf("%d",&x);
printf("Marks=%d",x);
printf("Grade is C\n");

2

break;
case 4:
printf("\nEnter marks of the student");
scanf("%d",&x);
printf("Marks=%d",x);
printf("Grade is D\n");
break;
case 5:
printf("\nEnter marks of the student");
scanf("%d",&x);
printf("Marks=%d",x);
printf("Grade is P\n");
break;
case 6:
printf("\nEnter marks of the student");
scanf("%d",&x);
printf("Marks=%d",x);
printf("Grade is F\n");
break;
case 7:
exit(0);
default:
printf("Wrong choice!\n");

}
}
return 0;
}

3
...
If income is between 5000 and 6000
then tax is 10% of the amount by which the income exceeds 5000
...
If
income is more than 15000 then the tax is 1900 + 30% of the amount by which the income
exceeds 15000
...
g
...
Write a program, which reads income and calculates the income tax
...
h>
#include ...
x<5000\n");
printf("2
...
6000printf("4
...
exit\n");
printf("your choice?\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter Income");
scanf("%d",&x);
printf("No income tax\n");
break;
case 2:
printf("\nEnter Income");
scanf("%d",&x);
y=(x-5000)*10/100;
printf("Tax to be paid is:%d\n",y);
break;
case 3:
printf("\nEnter Income");
scanf("%d",&x);
y=100+(x-6000)*20/100;
printf("Tax to be paid is:%d\n",y);
break;
case 4:
printf("\nEnter Income");
scanf("%d",&x);
y=1900+(x-15000)*30/100;
printf("Tax to be paid is:%d\n",y);
break;
case 5:
exit(0);
default:
printf("Wrong choice!\n");
}

}
return 0;
}

4
...
Y = X + 10 if X is 6
...
Y is 2 ∗ X + 4 if X is 12
...

#include ...
h>
int main()
{
int choice,x,y;
while(1)
{
printf("\n1
...
x=7\n");
printf("3
...
otherwise\n");
printf("5
...
Write a program, which reads three integers X, Y and Z and prints Y + Z if X is 0
...
If X is 2 then Y ∗ Z is printed
...

#include ...
h>
int main()
{
int choice,x,y,z,s;
while(1)
{
printf("\n1
...
x=7\n");
printf("3
...
x=3\n");
printf("5
...
Write program, which find the sum of first digits
#include ...
Write program, which finds sum of those numbers whose first digit is 1
#include ...
Write program, which finds sum of numbers after deleting first digit
...
h>
main( )
{ int n,i,u,v,sum,digit,x;
scanf("%d",&n);

8

sum=0;
for (i=1;i<=n;i++)
{ scanf("%d",&x);
while (x>0)
{
u=x/10;
v=u*10;
x=x-v;
sum=sum+x;
}
}
printf("Answer=%d",sum);
}

4
...

#include ...
Write program, which finds sum of numbers after incrementing every even digit
...
h>
main( )
{ int n,i,u,v,w,t,sum,digit,x;
scanf("%d",&n);
sum=0;
for (i=1;i<=n;i++)
{ scanf("%d",&x);
{
u=x/10;
v=x%10;
if(u%2==0)
u=u+1;
if(v%2==0)
v=v+1;
x=(u*10)+v;
{
sum=sum+x;}
}
}
printf("Answer=%d",sum);
}

6
...
h>

10

main( )
{ int n,i,u,v,sum,digit,x;
scanf("%d",&n);
sum=0;
for (i=1;i<=n;i++)
{ scanf("%d",&x);
{
u=x/10;
v=x%10;{
if(u>v)
x=u;
else
x=v;}
sum=sum+x;
}
}
printf("Answer=%d",sum);
}

7
...

#include ...
Write program, which finds the biggest smallest factor
#include ...
Write program, which reads a number and finds (sum of digits)smallest factor
...
h>
int main(void)
{
int j,sum=0,n,r=0,q,x;
printf("Enter number");
scanf("%d",&n);
for(j=2;j{
if(n%j==0)
{
q=j;
break;
}
}
while(n>0){
r=n%10;
sum+=r;
n/=10;}
x=pow(sum,q);
printf("\nThe smallest factor=%d",q);
printf("\nSum=%d",sum);
printf("\nThe computation of%d power%d =%d",sum,q,x);
return 0;
}

13

10
...
Find sum of greatest common divisors of pair of numbers
...
h>
int main(void)
{
int i,j,sum=0,n,arr[100],gcd=0,k=0;
printf("Enter number");
scanf("%d",&n);
for(i=0;i<2*n;i++)
{
scanf("%d",arr+i);
}
for(i=0;i<2*n;i++)
{
i=i+k;
for(j=1;j<=arr[i]&&arr[i+1];j++)
{
if(arr[i]%j==0&&arr[i+1]%j==0)
{
gcd=j;
break;
}
}
sum+=gcd;
gcd=0;
k=1;}
printf("Sum of all gcds=%d",sum-1);
return 0;
}

14

11
...
h>
int main(void)
{
int a,b,c,s=0,p,m=1,q;
printf("Enter a,b and c");
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
for(int i=a;i<=b;i++){
p=i;
q=c;
while(q!=0){
m*=p;
p=p+1;
q=q-1;
}
s+=m;
m=1;
}
printf("\nThe output is%d",s);
return 0;
}

15

12
...
h>
#include ...
Write program, which reads two numbers and computes output in the following manner
...
h>
#include ...
Write program, which reads n and n numbers
...

#include ...
Solve the system of equations of example 1 and example 3 using Gauss Jacobi 2x-y+z=
2, -x+3y+3z=3, 2x+y+4z=1
7x+y+2z=10,x+8y+3z=8,2x+3y+9z=6
#include ...
h>
#include ...
00001,sum;
int i,j,n,flag;
printf("\nEnter number of variables: ");
scanf("%d",&n);
printf("\nEnter the coefficients row-wise: ");
for(i=0;i{
for(j=0;j{
scanf("%f",&a[i][j]);
}
}
printf("\nEnter right hand vector: ");

18

for(i=0;iscanf("%f",&b[i]);
for(i=0;ix[i]=0;
//checking for row dominance
flag=0;
for(i=0;i{
sum=0;
for(j=0;jif(i!=j)
sum+=fabs(a[i][j]);
if(sum>fabs(a[i][i]))
flag=1;
}
//checking for column dominance
if(flag==1)
flag=0;
for(j=1;j{
sum=0;
for(i=1;iif(i!=j)
sum+=fabs(a[i][j]);
if(sum>fabs(a[j][j]))
flag=1;
}
if(flag==1)
{
printf("The coefficient matrix is not diagonally dominant \n");
printf("The Gauss-Jacobi method does not converge surely");
exit(0);
}
for(i=0;iprintf(" x[%d] ",i);
printf("\n");
do
{
for(i=0;i{
sum=b[i];
for(j=0;jif(j!=i)
sum-=a[i][j]*x[j];
xn[i]=sum/a[i][i];
}
for(i=0;iprintf("%8
...


printf("Solutoin is \n");
for(i=0;iprintf("%8
...


3, 4, 5
...

3
...
h>
void main()
{
float a[10][10],l[10][10],u[10][10],z[10],x[10],b[10];
int i,j,k,n;
printf("\nEnter the size of the coefficient matrix: ");
scanf("%d",&n);
printf("Enter the elements row-wise: ");
for(i=0;ifor(j=0;jscanf("%f",&a[i][j]);
printf("Enter the right hand vector: ");
for(i=0;iscanf("%f",&b[i]);

20

//Computation of L and U matrices
for(i=0;il[i][1]=a[i][1];
for(j=2;j<=n;j++)
u[1][j]=a[1][j]/l[1][1];
for(i=0;iu[i][i]=1;
for(i=2;i<=n;i++)
for(j=2;j<=n;j++)
if(i>=j)
{
l[i][j]=a[i][j];
for(k=1;k<=j-1;k++)
l[i][j]-=l[i][k]*u[k][j];
}
else
{
u[i][j]=a[i][j];
for(k=1;k<=j-1;k++)
u[i][j]=-l[i][k]*u[k][j];
u[i][j]/=l[i][i];
}
printf("\nThe lower triangular matrix L: \n");
for(i=0;i<=n;i++)
{
for(j=0;jprintf("%f ",l[i][j]);
printf("\n");
}
printf("\nThe upper triangular matrix U: \n");
for(i=0;i<=n;i++)
{
for(j=0;jprintf(" ");
for(j=i;jprintf("%f ",l[i][j]);
printf("\n");
}
//solve Lz=b by forward substitution
z[1]=b[1]/l[1][1];
for(j=1;i{
z[i]=b[i];
for(j=0;jz[i]-=l[i][j]*z[j];
z[i]/=l[i][i];
}
//solve Ux=z by backward substitution
x[n]=z[n];
for(i=n-1;i>=0;i--)
{
x[i]=z[i];
for(j=i+1;jx[i]-=u[i][j]*x[j];
}
printf("The solution is: ");
for(i=0;iprintf("%f ",x[i]);

21

}

4
...
h>
void main()
{
float a[10][10],l[10][10],u[10][10],z[10],x[10],b[10];
int i,j,k,n;
printf("\nEnter the size of the coefficient matrix: ");
scanf("%d",&n);
printf("Enter the elements row-wise: ");
for(i=0;ifor(j=0;jscanf("%f",&a[i][j]);
printf("Enter the right hand vector: ");
for(i=0;iscanf("%f",&b[i]);
//Computation oof L and U matrices
for(i=0;i
l[i][i]=1;
for(i=2;i<=n;i++)
l[i][1]=a[i][1];
for(j=2;j<=n;j++)
u[1][j]=a[1][j]/l[1][1];
for(i=0;ifor(j=2;j<=n;j++)
if(i>=j)
{
l[i][j]=a[i][j];
for(k=1;k<=j-1;k++)
l[i][j]-=l[i][k]*u[k][j];
}
else
{
u[i][j]=a[i][j];
for(k=1;k<=j-1;k++)
u[i][j]=-l[i][k]*u[k][j];
u[i][j]/=l[i][i];
}
printf("\nThe lower triangular matrix L: \n");

22

}

for(i=0;i<=n;i++)
{
for(j=0;jprintf("%f ",l[i][j]);
printf("\n");
}
printf("\nThe upper triangular matrix U: \n");
for(i=0;i<=n;i++)
{
for(j=0;jprintf(" ");
for(j=i;jprintf("%f ",l[i][j]);
printf("\n");
}
//solve Lz=b by forward substitution
z[1]=b[1]/l[1][1];
for(j=1;i{
z[i]=b[i];
for(j=0;jz[i]-=l[i][j]*z[j];
z[i]/=l[i][i];
}
//solve Ux=z by backward substitution
x[n]=z[n];
for(i=n-1;i>=0;i--)
{
x[i]=z[i];
for(j=i+1;jx[i]-=u[i][j]*x[j];
}
printf("The solution is: ");
for(i=0;iprintf("%f ",x[i]);

6,7
...
05 and then modify both programs according to the
modified Euler’s method and R-K’s order 2 method
...


23

#include ...
h>
double f(double t, double y)
{
return y;
}
int main()
{
double h=0
...
0; y0 = 1
...
0;
x=0;
printf("t Euler Exact\n");
for (i=0; i<= 10; i++)
{
printf("t= %lf %lf %lf\n", t, y, exp(t));
y=y0+(h/2)*(f(x,y0)+f(t,y));
t=t+h;
}
return 0;
}

10
...
h>
#include ...
05, t, y, k1,k2;
int i;
/* initial value */
t=0
...
0;
for (i=0; i<=10; i++)
{
printf("t= %lf rk= %lf exact=%lf\n", t, y, exp(t));
k1=h*f(t,y);
k2=h*f(t+h, y+k1);
y= y+(k1+k2)/2
Title: C+ program
Description: C+ programming for computational technique assigent