Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views52 pages

Assignment 1 Mahbub Sir v2

Uploaded by

Glowing Brain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views52 pages

Assignment 1 Mahbub Sir v2

Uploaded by

Glowing Brain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

Assignment 1: Basic

Declaration and Expression

Name: ROWNAK ISLAM NABIL


UNIVERSITY ID: 2302038
SESSION: 23-24
UNIVERSITY NAME: PATUAKHALI SCIENCE
AND TECHNOLOGY UNIVERSITY
MOBILE: 01646552090

Submitted To:
Md.Mahbubur Rahman
Assistant Professor in CSIT
Faculty of Computer Science And Technology University
Patuakhali Science and Technology University-PSTU
Dumki, Patuakhali-8602
Solution 1:

#include <stdio.h>

int main(){

printf("Name :Rownak Islam Nabil \n");

printf("DOB :December 12, 2004 \n");

printf("Mobile :01646552090 \n");

OUTPUT:

Solution 2:

#include <stdio.h>

int main(int argc, char** argv) {

// Check for C standard version

#if __STDC_VERSION__ >= 201710L

printf("We are using C18!\n");

#elif __STDC_VERSION__ >= 201112L

printf("We are using C11!\n");

#elif __STDC_VERSION__ >= 199901L

printf("We are using C99!\n");

#else

printf("We are using C89/C90!\n");

#endif

// Indicate successful execution


return 0;

OUTPUT:

Solution 3:

#include <stdio.h>

int main(){

//Printing the F

printf(" ######\n #\n #\n #####\n #\n #\n #\n\n");

//Printing the C

printf(" ######\n ## ##\n #\n #\n #\n #\n #\n ## ##\n ######");}
OUTPUT:

Solution 4:

#include <stdio.h>

int main(){

char x,m,l;

char arr[2];

x='X';

m='M';

l='L';

arr[0]=x;

arr[1]=m;

arr[2]=l;

printf("The reverse of XML is ");

for(int i=2;i>=0;i--){printf("%c",arr[i]);}

OUTPUT:

Solution 5:
#include <stdio.h>

int main(){

int height,width;

height=7;

width=5;

int perimeter=2*(height+width);

int area=height*width;

printf("Perimeter of the rectangle = %d inches \n",perimeter);

printf("Area of the rectangle = %d square inches",area);

OUTPUT:

Solution 6:

#include <stdio.h>

#include <math.h>

#define PI 3.1416

int main(){

float radius=6;

float perimeter=2*PI*radius;

float area=PI*pow(radius,2);

printf("Perimeter of the circle = %.4f inches \n",perimeter);

printf("Area of the circle = %.4f square inches",area);

OUTPUT:
Solution 7:

#include<stdio.h>

int main()

int day,week,year;

day=1329;

year=day/365;

int weekDay=(day-(year*365));

week=weekDay/7;

int DinTheDay=weekDay-(7*week);

day=DinTheDay;

printf("Number of days : %d \n",day);

printf("Expected Output : \n Years: %d \n",year);

printf("Weeks : %d \n",week);

printf("Days : %d\n",day);

OUTPUT:

Solution 9:

#include <stdio.h>

int main(){
int num1,num2,sum;

printf("Enter the first integer : ");

scanf("%d",&num1);

printf("Enter the second integer : ");

scanf("%d",&num2);

sum=num1+num2;

printf("Sum of the above two integers = %d",sum);

}OUTPUT:

Solution 10:

#include <stdio.h>

int main(){

int num1,num2,mult;

printf("Enter the first integer : ");

scanf("%d",&num1);

printf("Enter the second integer : ");

scanf("%d",&num2);

mult=num1*num2;

printf("Multiplication of the above two integers = %d",mult);

OUTPUT:

Solution 11:
#include <stdio.h>

int main(){

int weight1,weight2,num1,num2;

float avg;

printf("Enter the first Item's Weight : ");

scanf("%d",&weight1);

printf("How many of the First item?(in number) : ");

scanf("%d",&num1);

printf("Enter the second Item's Weight : ");

scanf("%d",&weight2);

printf("How many of the second item?(in number) : ");

scanf("%d",&num2);

avg=num1*weight1;

avg=avg+(num2*weight2);

avg=(avg)/(num1+num2);

printf("Average Value is = %f",avg);

/*

avg=((num1*weight1)+(num2*weight2))/(num1+num2);

If you code like the above,

the output will be in just int(not accurate).

instead,Here you have to use float for all the input to output accurately.

*/

}
OUTPUT:

Solution 12:

#include<stdio.h>

int main(){

char id[10];

float perHr,hr,salary;

printf("Input the Employees ID(Max. 10 chars):");

scanf("%s",id);//why it's working without &

printf("Input the working hrs:");

scanf("%f",&hr);

printf("Salary amount/hr:");

scanf("%f",&perHr);

salary=hr*perHr;

printf("Expected Output:\n");

//to print 2 digits after decimal

printf("Employees ID = %s \n",id);

printf("Salary = U$ %.2f",salary);

OUTPUT:
Solution 13:

#include<stdio.h>

int main(){

int a,b,c;

printf("Input First Number :");

scanf("%d",&a);

printf("Input Second Number :");

scanf("%d",&b);

printf("Input Third Number :");

scanf("%d",&c);

if(a>b){

if(a>c){printf("%d is the greatest number among the given three numbers",a);}

else{printf("%d is the greatest number among the given three numbers",c);}

else{

if(b>c){printf("%d is the greatest number among the given three numbers",b);}

else{printf("%d is the greatest number among the given three numbers",c);}

}
OUTPUT:

Solution 14:

#include <stdio.h>

int main(){

/*

given total distance (integer value) travelled (in km)

and spent fuel (in litters, float number – 2 decimal points)

*/

int km;float fuel;

printf("Input total distance in km:");

scanf("%d",&km);

printf("Input total fuel spent in liters:");

scanf("%f",&fuel);

printf("the average consumption in (km/lt) is :%.2f",km/fuel);

OUTPUT:

Solution 15:

#include<stdio.h>

#include<math.h>

int main(){

float x1,x2,y1,y2,distance;

printf("Input x1 :");
scanf("%f",&x1);

printf("Input y1 :");

scanf("%f",&y1);

printf("Input x2 :");

scanf("%f",&x2);

printf("Input y2 :");

scanf("%f",&y2);

distance=sqrt(pow((x1-x2),2)+pow((y1-y2),2));

printf("The distance is %f",distance);

OUTPUT:

Solution 16:

#include<stdio.h>

int main(){

int taka;

printf("Enter the amount :");

scanf("%d",&taka);

printf("%d Note(s) of 100.00 \n",taka/100);

taka=taka%100;

printf("%d Note(s) of 50.00 \n",taka/50);

taka=taka%50;

printf("%d Note(s) of 20.00 \n",taka/20);

taka=taka%20;

printf("%d Note(s) of 10.00 \n",taka/10);


taka=taka%10;

printf("%d Note(s) of 5.00 \n",taka/5);

taka=taka%5;

printf("%d Note(s) of 2.00 \n",taka/2);

taka=taka%2;

printf("%d Note(s) of 5.00 \n",taka);

OUTPUT:

Solution 17:

#include <stdio.h>

int main(){

int sec,hour,min,temp;

printf("Input seconds : ");

scanf("%d",&sec);

hour=sec/3600;

temp=sec%3600;

min=(temp)/60;

sec=(temp%60);

printf("There are : \n H:M:S - %d:%d:%d",hour,min,sec);


}

OUTPUT:

Solution 18:

#include<stdio.h>

int main(){

int p,q,r,s;

printf("p:");

scanf("%d",&p);

printf("q:");

scanf("%d",&q);

printf("r:");

scanf("%d",&r);

printf("s:");

scanf("%d",&s);

if((q>0 && r>0 && s>0) && (p%2==0))

if(q>r && s>p && ((r+s)>(p+q)))

printf("Correct Values.\n");

else{

printf("Wrong Values");

}
}

else{

printf("Wrong Values");

OUTPUT:

Solution 20:

#include<stdio.h>

#include<math.h>

void take_input(int *xsq, int *xnorm, int *cons);

int main()

int xsq,xnorm,cons;

float a,b,c,rt1,rt2;

do{

take_input(&xsq,&xnorm,&cons);

if(xsq==0)

{printf("It won't be a Quadratic Equation\n");}

while(xsq==0);

a=xsq;b=xnorm;c=cons;
// if((pow(b,2)-4*a*c)<0){printf("THE VALUES ARE GETTING UNREAL?!...\n LET'S
START AGAIN");}

rt1=(-b+sqrt(pow(b,2)-4*a*c))/(2*a);

rt2=(-b-sqrt(pow(b,2)-4*a*c))/(2*a);

printf("The equation is (%d)X-squared+(%d)X+(%d).\n Root1 is : %f \n Root2 is :


%f",xsq,xnorm,cons,rt1,rt2);

void take_input(int *xsq, int *xnorm, int *cons){

printf("Enter the (X^2) Coefficient of the Equation(a) : ");

scanf("%d",xsq);

//here &xsq vs xsq....learn later

printf("Enter the (X) Coefficient of the Equation(b) : ");

scanf("%d",xnorm);

printf("Enter the (constant) of the Equation(c) : ");

scanf("%d",cons);

OUTPUT:

Solution 21:

#include<stdio.h>

int main(){

int num;
printf("Enter a number: ");

scanf("%d",&num);

if(num>=0 && num<=80)

//[0, 20], [21, 40], [41, 60], [61, 80]

if(num<=20){printf("range:[0,20]");}

else if(num<=40){printf("range:[21,40]");}

else if(num<=60){printf("range:[41,60]");}

else if(num<=80){printf("range:[61,80]");}

else{printf("Error\n");}

OUTPUT:

Solution 22:

#include <stdio.h>

int main() {

int num[5];

int oddsum = 0;

printf("Input the first number: ");

scanf("%d", &num[0]);

printf("Input the second number: ");

scanf("%d", &num[1]);
printf("Input the third number: ");

scanf("%d", &num[2]);

printf("Input the fourth number: ");

scanf("%d", &num[3]);

printf("Input the fifth number: ");

scanf("%d", &num[4]);

for(int i=0;i<5;i++){

if(num[i]%2==1){

oddsum=oddsum+num[i];}

printf("Sum of all odd values is : %d\n", oddsum);

OUTPUT:

Solution 23:

#include <stdio.h>

int main() {

float a, b, c, p;

printf("Input the first number: ");

scanf("%f", &a);

printf("Input the second number: ");

scanf("%f", &b);

printf("Input the third number: ");


scanf("%f", &c);

if (a + b > c && a + c > b && b + c > a) {

p = a + b + c;

printf("Perimeter = %.2f\n", p);

} else {

printf("Not valid triangle\n");

OUTPUT:

Solution 24:

#include <stdio.h>

int main() {

int x, y;

printf("\nInput the first number: ");

scanf("%d", &x);

printf("\nInput the second number: ");

scanf("%d", &y);

if(y > x)

int temporary;

temporary = y; // Swap the values of 'x' and 'y'

//THis part is important.

y = x;
x = temporary;

if((x % y)== 0)

printf("\nMultiplied!\n");}

else

printf("\nNot Multiplied!\n");

OUTPUT:

Solution 25:

#include<stdio.h>

int main(){

int num;

printf("Input a number between 1 to 12 to get the month name: ");

scanf("%d",&num);

switch(num){

case 1:printf("January");break;

case 2:printf("February");break;

case 3:printf("March");break;
case 4:printf("April");break;

case 5:printf("May");break;

case 6:printf("June");break;

case 7:printf("July");break;

case 8:printf("Agust");break;

case 9:printf("September");break;

case 10:printf("October");break;

case 11:printf("November");break;

case 12:printf("December");break;

default:printf("Input a number between 1 to 12.");

OUTPUT:

Solution 26:

#include <stdio.h>

int main(){

for(int i=1;i<=50;i++){

if(i%2==0){printf("%d ",i);}
}

OUTPUT:

Solution 27:

#include <stdio.h>

int main() {

int num[5];

int pos = 0,neg =0;

printf("Input the first number: ");

scanf("%d", &num[0]);

printf("Input the second number: ");

scanf("%d", &num[1]);

printf("Input the third number: ");

scanf("%d", &num[2]);

printf("Input the fourth number: ");

scanf("%d", &num[3]);

printf("Input the fifth number: ");

scanf("%d", &num[4]);

for(int i=0;i<5;i++){

if(num[i]>0){

pos++;}

else if(num[i]<0){
neg++;}

printf("There are %d positive and %d negative numbers",pos,neg);

OUTPUT:

Solution 28:

#include <stdio.h>

int main() {

int num[5],pos = 0;

float avg=0;

printf("Input the first number: ");

scanf("%d", &num[0]);

printf("Input the second number: ");

scanf("%d", &num[1]);

printf("Input the third number: ");

scanf("%d", &num[2]);

printf("Input the fourth number: ");

scanf("%d", &num[3]);

printf("Input the fifth number: ");

scanf("%d", &num[4]);

for(int i=0;i<5;i++){

if(num[i]>0){
pos++;avg=avg+num[i];}

avg=avg/pos;

printf("There are %d positive numbers and %f is the average of them.\


n",pos,avg);

OUTPUT:

Solution 29:

#include <stdio.h>

int main() {

int num[5],odd = 0;

float avg=0;

printf("Input the first number: ");

scanf("%d", &num[0]);

printf("Input the second number: ");

scanf("%d", &num[1]);

printf("Input the third number: ");

scanf("%d", &num[2]);

printf("Input the fourth number: ");

scanf("%d", &num[3]);

printf("Input the fifth number: ");

scanf("%d", &num[4]);
for(int i=0;i<5;i++){

if(num[i]%2==1){

odd=odd+num[i];}

printf("The sum of the odd numbers is %d.\n",odd);

OUTPUT:

Solution 30:

#include <stdio.h>

int main(){

int num;

printf("Input Number:");

scanf("%d",&num);

for(int i=1;i<=num;i++){

if(i%2==0){

printf(" %d^2 = %d \n",i,(i*i));

}}

OUTPUT:
Solution 31:

#include <stdio.h>

int main(){

int num;

printf("Enter a number:");

scanf("%d",&num);

if(num==0){printf("Even ");}

else{

if(num>0){printf("positive ");}

else{printf("negative ");}

if(num%2==0){printf(" even");}

else{printf(" odd");}

OUTPUT:

Solution 32:

#include <stdio.h>

int main(){

int num;

printf("Enter a number:");

scanf("%d",&num);

for(int i=1;i<=100;i++){

if(i%num==3){printf("%d\n",i);}

}
}

OUTPUT:

Solution 33:

#include <stdio.h>

int main() {

int num[5];

printf("Input the first number: ");

scanf("%d", &num[0]);

printf("Input the second number: ");

scanf("%d", &num[1]);

printf("Input the third number: ");

scanf("%d", &num[2]);

printf("Input the fourth number: ");

scanf("%d", &num[3]);

printf("Input the fifth number: ");

scanf("%d", &num[4]);

int max=num[0];

for(int i=0;i<5;i++){

if(num[i]>max){max=num[i];}
}

printf("the max number from them is %d",max);

OUTPUT:

Solution 34:

#include <stdio.h>

int main(){

int num1,num2,sum=0,count=0;

printf("Input a pair of numbers (for example 10,2):\n");

printf("Input first number of the pair:");

scanf("%d",&num1);

printf("Input second number of the pair:");

scanf("%d",&num2);

if(num2>num1){

int temp;

temp=num2;

num2=num1;

num1=temp;

for(int i=num2;i<=num1;i++)

if(i%2==1){
count=count+1;

sum=sum+i;

printf("Expected Output:\nList of odd numbers: %d\n",count);

for(int i=num2;i<=num1;i++)

if(i%2==1){

printf("%d\n",i);

printf("Sum:%d",sum);

OUTPUT:

Solution 35:

#include<stdio.h>

int main(){

int num1,num2;

printf("Input a pair of numbers (for example 10,2 : 2,10):\n");

printf("Input first number of the pair:");

scanf("%d",&num1);
printf("Input second number of the pair:");

scanf("%d",&num2);

if(num1>num2){printf("The pair is in descending order!");}

else{printf("The pair is in ascending order!");}

OUTPUT:

Solution 36:

#include <stdio.h>

#include <string.h>

int main() {

char str[] = "1234";

char test[6];

int ask(){ scanf("%s",&test);

if (strcmp(str, test) == 0) {

printf("The strings are equal.\n");

else {

printf("The strings are not equal.\n");

ask();

}}

ask();

OUTPUT:
Solution 37:

int main() {

int x, y;

printf("Input the Coordinate(x,y): ");

printf("\nx: ");

scanf("%d", &x);

printf("y: ");

scanf("%d", &y);

if(x > 0 && y > 0) {

printf("Quadrant-I(+,+)\n");

else if(x > 0 && y < 0) {

printf("Quadrant-II(+,-)\n");

else if(x < 0 && y < 0) {

printf("Quadrant-III(-,-)\n");

else if(x < 0 && y > 0) {

printf("Quadrant-IV(-,+)\n");

}
OUTPUT:

Solution 38:

#include <stdio.h>

int main(){

float num1,num2;float result;

printf("Enter 1st number :");

scanf("%f",&num1);

printf("Enter 2nd number :");

scanf("%f",&num2);

if(num2!=0)

printf("%f",num1/num2);

else{printf("Division is not possible");}

OUTPUT:

Solution 39:

#include <stdio.h>

int main(){

int num1,num2,result=0;
printf("Enter 1st number :");

scanf("%d",&num1);

printf("Enter 2nd number :");

scanf("%d",&num2);

if(num1>num2){

int temp=num2;

num2=num1;

num1=temp;

for(int i=num1;i<=num2;i++)

if(!(i%17==0)){ result=result+i;}

printf("Sum: %d",result);}

OUTPUT:

Solution 40:

#include <stdio.h>

int main(){

int num1,num2;

printf("Enter 1st number :");

scanf("%d",&num1);

printf("Enter 2nd number :");

scanf("%d",&num2);
if(num1>num2){

int temp=num2;

num2=num1;

num1=temp;

for(int i=num1;i<=num2;i++)

if((i%7==2)||(i%7==3)){ printf("%d \n",i);}

}}

OUTPUT:

Solution 41:

#include<stdio.h>

int main(){

int num;

printf("Enter number (n) :");

scanf("%d",&num);

int max=1;

for(int i=1;i<num;i++)

{
for(int j=0;j<3;j++){

printf(" %d ",max);

max++;

printf("\n");

OUTPUT:

Solution 42:

#include<stdio.h>

int main(){

int num;

printf("Enter number (n) :");

scanf("%d",&num);

for(int i=1;i<=num;i++)

printf(" %d %d %d \n",i,i*i,i*i*i);

printf("\n");

}
OUTPUT:

Solution 43:

#include <stdio.h>

int main(){

int no_line,in_line;

printf("Input number of lines:");

scanf("%d",&no_line);

printf("Number of characters in a line:");

scanf("%d",&in_line);

int num=1;

for(int i=0;i<no_line;i++){

for(int j=0;j<in_line;j++){

printf(" %d ",num);

num++;

printf("\n");

OUTPUT:
Solution 44:

OUTPUT:

Solution 45:

OUTPUT:

Solution 46:

OUTPUT:

Solution 47:

OUTPUT:

Solution 48:

#include <stdio.h>

int main() {

float marks, sum = 0;

int count = 0;

printf("Input Mathematics marks (0 to terminate): ");


while (1) {

scanf("%f", &marks);

if (marks <= 0) {

break;

}sum += marks;

count++;}

if (count > 0) {

printf("Average marks in Mathematics: %.2f\n", sum / count);}

else {

printf("No valid marks entered.\n");}

OUTPUT:

Solution 49:

#include <stdio.h>

int main() {

int arr[7];

int i;

printf("Input the first number of the array: ");

scanf("%d", &arr[0]);

for (i = 1; i < 7; i++) {

arr[i] = arr[i - 1] * 3;
}

printf("Array elements: ");

for (i = 0; i < 7; i++) {

printf("%d ", arr[i]);

printf("\n");

return 0;

OUTPUT:

Solution 50:

#include <stdio.h>

int main() {

int num[5];

printf("Input the first number: ");

scanf("%d", &num[0]);

printf("Input the second number: ");

scanf("%d", &num[1]);

printf("Input the third number: ");

scanf("%d", &num[2]);

printf("Input the fourth number: ");

scanf("%d", &num[3]);

printf("Input the fifth number: ");


scanf("%d", &num[4]);

for(int i=0;i<5;i++){

if(num[i]<5){printf("A[%d]=%d \n",i,num[i]);}

OUTPUT:

You might also like