Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

ASSIGNMENT

DEPARTMENT:

B.S IT

SUBJECT :

PROGRAMMING

ROLL NO :

1750

SUBMITTED TO:

MAM ROMANA

SUBMITTED BY:

RABBIA RAFAQAT

PROGRAM:1
#include<stdio.h>
#include<conio.h>
main()
{
int x,y;
char c;
printf ("enter coordinates x:");
scanf ("%d",&x);
printf ("\nenter coordinates y:");
scanf ("%d",&y);
printf ("\nenter direction:");
scanf("%s",&c);
switch(c)
{
case'E':
case'e':
x++;
printf("x=%d",x);
break;
case'W':
case'w':
x--;
printf("x=%d",x);
break;
case'N':
case'n':
y++;
printf("%d",y);
break;
case'S':
case's':
y--;
printf("y=%d",y);
break;
default:

printf("/nyou enter invalid direction");


}
getch();
}

PROGRAM: 2
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d;
printf("Enter value ofA:");
scanf("%d",&a);
printf("Enter value ofB:");
scanf("%d",&b);
printf("Enter value ofC:");
scanf("%d",&c);
printf("Enter value ofD:");
scanf("%d",&d);
(a>b)?((c>d)?printf("\n%d",cd):printf("\n%d",c+d)):((c>d)?printf("\n%d",4*c):printf("\n%d",3
*d));
getch();
}
}

PROGRAM: 3
#include<stdio.h>
#include<conio.h>
int main()
{
int m,n,i,j;
printf("Enter any number: ");
scanf("%d", &m);
for(n=2; n<=m; n++)
{
for(i=2; i<n; i++)
{
if(n%i==0)
{
j=0;
break;
}
j=1;
}

if(j)
printf("%d\n",n);
}
getch();
return 0;
}

PROGRAM:4
#include <stdio.h>
#include <conio.h>
main()
{
int i=1,a,b,c;
printf("ARMSTRONG NUMBERS BETWEEN 1 to 500 ARE \n");
while (i<=500)
{
a=i%10;
b=i%100;
b=(b-a)/10;
c=i/100;
if ((a*a*a)+(b*b*b)+(c*c*c)==i)
printf("%d\n",i);
i++;
}
getch();
}

PROGRAM:5
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int n;
srand(time(0));
n = rand() % 91 + 10;
printf("The randomly(10 to 100) selected number is :
%d",n);
return 0;
}

PROGRAM:6

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int num, guess, tries = 0;
srand(time(0)); //seed random number generator
num = rand() % 100 + 1; // random number between 1 and 100
cout << "Guess My Number Game\n\n";
do
{
cout << "Enter a guess between 1 and 100 : ";
cin >> guess;
tries++;
if (guess > num)
cout << "Too high!\n\n";
else if (guess < num)
cout << "Too low!\n\n";
else
cout << "\nCorrect! You got it in " << tries << "
guesses!\n";
} while (guess != num);
cin.ignore();
cin.get();
return 0;
}

PROGRAM:7
#include<stdio.h>
#include<conio.h>
int main()
{
int user_input;
printf("Please enter an integer\n__");
scanf("%d", &user_input);
printf("Is %d divisible by 5 and 6? ", user_input);
if((user_input%5) == 0 && (user_input%6) == 0)
{
printf("true\n");

}
else
{
printf("false\n");
}
printf("Is %d divisible by 5 or 6? ", user_input);
if((user_input%5) == 0 || (user_input%6) == 0)
{
printf("true\n");
}
else
{
printf("false\n");
}
getch();
return 0;
}

You might also like