Assignment 1 PPS

 Assignment 1


Problem 1: Write a program in C to display a message “Welcome to C Programming” on the screen.

sol.    

#include<stdio.h>

main()

{

printf("Welcome to C Programming");

return 0;

}


Problem 2: Modify program no. 1 to display a multiline message on the screen using /n character.

sol. 

#include<stdio.h>

main()

{

printf("Welcome to C Programming \n" "This code is modifide for print multiline message on the screen \n" "Is this code is correct?");

return 0;

}


Problem 3: Write a program in C to calculate and display the sum of two numbers using integer variables.

sol.

#include<stdio.h>

int main()

{

int a,b,sum;

printf("Enter the numbers\n");

scanf("%d%d",&a,&b);

sum=a+b;

printf("sum=%d",sum);

return 0;

}


Problem 4: Modify program no. 3 to accept two integer numbers, X and Y from the user and then compute their sum, S = X + Y. Display the message “Sum of X and Y is S” as output on the screen.

sol.

#include<stdio.h>

int main()

{

int x,y,sum;

printf("x=");

scanf("%d",&x);

printf("y=");

scanf("%d",&y);

sum=x+y;

printf("sum of x and y is = %d",sum);

return 0;

}


Problem 5: Write a program in C to compute the expression, a2 – b2 and display the result on the screen.

sol.

#include<stdio.h>

#include<math.h>

main()

{

int a,b,c;

printf("a = ");

scanf("%d",&a);

printf("b = ");

scanf("%d",&b);

c=pow(a,2)-pow(b,2);

printf("result = %d",c);

return 0;

}

KRISHNA

Author & Editor

Thanks for visiting xmonocodes , i hope you are getting everything you want.

0 comments:

Post a Comment