Program C
Program C
h>
#include<math.h>
printf("%d", x % 2 == 0);
//(if divisible ,then output=1(means true) & if not divisible ,then
output=0(means false).)
return 0;
}*/
int x;
printf("enter a number : ");
scanf("%d", &x);
printf("%d", x % 2 == 0);
return 0;
}*/
return 0;
}*/
//5.write a program for checking adolescent & the work they can do.
/*int main(){
int age;
printf("Enter your age : ");
scanf("%d", &age);
else{
printf("No,you are not adult \n");
}
printf("Thank you");
return 0;
}*/
age >= 18 ? printf("You are adult \n") : printf("You are not adult \n");
return 0;
}*/
else{
printf("You are a child");
}
return 0;
}*/
switch (day){
case 1 : printf("It's Monday \n");
break;
case 2 : printf("It's Tuesday \n");
break;
case 3 : printf("It's Wednesday \n");
break;
case 4 : printf("It's Thursday \n");
break;
case 5 : printf("It's Friday \n");
break;
case 6 : printf("It's Saturday \n");
break;
case 7 : printf("It's Sunday \n");
break;
if(number >= 0 ){
printf("It's +ve \n");
if(number % 2 == 0 ){
printf("It's even \n");
} else {
printf("It's odd \n");
}
} else {
printf("It's -ve \n");
if(number % 2 == 0 ){
printf("It's -ve even \n");
} else {
printf("It's -ve odd \n");
}
}
return 0;
}*/
if(marks > 30 ){
printf("You are pass. \n");
printf("Congratulations \n");
} else {
printf("You are fail. \n");
printf("Focus on your study \n");
}
return 0;
}*/
//(you can also write in short by ternary oprator.) *very important*
/*int main(){
int marks;
printf("Enter your marks : ");
scanf("%d", &marks);
if(marks == 100 ){
printf("You are pass with 1st division.Also with distinction \n");
printf("Your grade is A+ \n");
printf("Outstanding \n");
}
return 0;
}*/
//10.looping system
//OR print number from 1 to 10
/*int main(){
for(int i=1; i<=10; i=i+1){
//(**Very Important**)
//(if i<=10 part is missing, then infinite loop system is
started.Which mack you memorey ful,untill it crush..)
//(i=i+1 OR i += 1 both are same.)*
//( + means each time value is increases by 1,then always use <= till
how many times.)
return 0;
}*/
//11.print the numbers from 0 to n, if n is given by user
/*int main(){
int n;
printf("enter a numer : ");
scanf("%d", &n);
return 0;
}*/
return 0;
}*/
//(another method)
/*int sum(int a, int b);
void printTable(int n);
int main(){
int n;
printf("Enter a number for creating table : ");
scanf("%d", &n);
return 0;
}
//13.keep taking numbers as input from user until user an odd number.
/*int main(){
int n;
do{
printf("enter a number : ");
scanf("%d", &n);
printf("%d \n", n);
if(n % 2 !=0){
break;
}
}while(1);
printf("You enter a odd number, that's why it's stop. \n");
printf("Thank You.");
return 0;
}*/
return 0;
}*/
return 0;
}*/
//17.factorial of a number n.
/*int main(){
int n;
printf("Enter a number to get factorial of the number : ");
scanf("%d", &n);
int fact = 1;
for(int i=1; i<=n; i++){
fact = fact * i;
}
printf("Final factorial is %d", fact);
return 0;
}*/
//18.write a function that prints Namaste if user is Indian & Bonjour if the
user is french.
//(declaration/prototype)
/*void Namaste();
void Bonjour();
int main(){
printf("Enter f for French & i for Indian : "); //(function call)
char ch;
scanf("%c", &ch);
if(ch=='i'){
Namaste();
} else{
Bonjour();
}
return 0;
}
void Namaste(){
printf("Namaste \n");
}
void Bonjour(){
printf("Bonjour \n");
}
//(function definition)
void printHello(){
printf("Hello! \n");
printf("Goodbye \n");
}*/
int main(){
float value = 100.0;
calculatePrice(value);
printf("Original value is : %f\n", value);
return 0;
}
int main(){
int n;
printf("Enter orginal price to get GST included price : ");
scanf("%d", &n);
calculatePrice(n);
printf("Original value is : %d\n", n);
return 0;
}
int main(){
printf("Factorial is : %d", fact(5));
return 0;
}
int fact(int n){
int main(){
float far = convertTemp(37);
printf("farhrenheight is : %f", far);
return 0;
}
int main(){
int science = 98;
int math = 95;
int sanskrit = 99;
int main(){
int a = 3, b = 5;
int sum, product, avg;
doWork(a, b, &sum, &product, &avg);
printf(" sum = %d\n product = %d\n avg = %d\n", sum, product, avg);
return 0;
}
//26.Write a program to enter price of 3 items & print their final cost with
GST.
/*int main(){
float price[3];
printf("Enter all 3 prices : ");
scanf("%f", &price[0]);
scanf("%f", &price[1]);
scanf("%f", &price[2]);
return 0;
}*/
//27.for a given arrey (int arr[] = {1,2,3,4,5}) ,what will the following
gives?
//a. *(arr+2) b. *(arr+4)
/*int countOdd(int arr[], int n);
int main(){
int arr[] = {1, 2, 3, 4, 5};
printf("%d \n", *(arr+2));
printf("%d \n", *(arr+4));
return 0;
}
return count;
}*/
marks[1][0] = 90;
marks[1][1] = 89;
marks[1][2] = 78;
int main(){
int arr[] = {1, 2, 3, 4, 5};
reverse(arr, 5);
//printArr(arr, 5);
return 0;
}
int main(){
int tables[2][10];
storeTables(tables, 0, 10, 2);
storeTables(tables, 1, 10, 3);
printf("\n");
//create a string firstname & lastName to store detials of user & print all
the characters using a loop.
int main(){
char firstName[] = "Imran";
char lastName[] ="Ali";
printstring(firstName);
printString(lastName);
return 0;
}
int main(){
char str[100];
fgets(str, 100, stdin);
puts(str);
return 0;
}
int main(){
char *canChange = "Hello Imran";
puts(canChange);
canChange = "Hello";
puts(canChange);
return 0;
}
int main(){
char name[100];
fgets(name, 100, stdin);
printf("length is : %d", countLength(name));
return 0;
}
int main(){
char name[] = "Imran";
int length = strlen(name);
printf("length is : %d", length);
return 0;
}
int main(){
char oldStr[] = "oldStr";
char newStr[] = "newString";
strcpy(newStr, oldStr);
puts(newStr);
}*/
int main(){
char firstStr[100] = "Hello";
char secString[] = "IMran";
strcat(firstStr, secString);
puts(firstStr);
}*/
else{
if(side2>side3){
sum=side1+side3; largeside = side2;
}
else{
sum=side1+side2; largeside = side3;
}
}
if(sum>largeside){
printf("the triangle is a valid triangle\n");
}
else{
printf("the triangle is an invalid triangle\n");
}
return 0;
}*/
//find the salted form of a password entered by user if the salt is "123" &
added at the end.
/*void salting(char password[]);
int main(){
char password[100];
scanf("%s", password);
salting(password);
}
//write a function named slice, which takes a string & returns a slice string
from index n to m.
/*void slice(char str[], int n, int m);
int main(){
char str[] = "HelloWorld";
slice(str, 3, 6);
}
void slice(char str[], int n, int m){ // n & m are valid value
char newStr[100];
int j = 0;
for(int i=n; i<=m; i++, j++){
newStr[j] = str[i];
}
newStr[j] = '\0';
puts(newStr);
}*/
int main(){
char str[] = "HelloImran";
printf("Vowels are : %d", countVowels(str));
}
int main(){
struct student s1;
s1.roll = 1664;
s1.cgpa = 9.2;
strcpy(s1.name, "Imran");
printf("\n");
return 0;
}*/
//another method
/*struct student{
char name[100];
int roll;
float cgpa;
};
int main(){
struct student s1 = {"Imran", 1662, 9.2};
printf("student name = %s\nstudent roll = %d\nstudent cgpa = %f\n",
s1.name, s1.roll, s1.cgpa);
printf("\n");
return 0;
}*/
int main(){
struct address adds[2];
//for input
printf("Enter info for person 1 : ");
scanf("%d", &adds[0].houseNo);
scanf("%d", &adds[0].block);
scanf("%s", adds[0].city);
scanf("%s", adds[0].state);
printAdd(adds[0]);
printAdd(adds[1]);
return 0;
}
int main(){
struct vector v1 = {5, 10};
struct vector v2 = {3, 7};
struct vector sum = {0};
int main(){
acc acc1 = {123, "Imran"};
acc acc2 = {124, "Anjum"};
acc acc3 = {125, "Gulnar"};
return 0;
}*/
int n;
fscanf(fptr, "%d", &n);
printf("Number = %d\n", n);
fclose(fptr);
return 0;
}*/
char name[100];
int roll;
float cgpa;
fclose(fptr);
return 0;
}*/
int n;
printf("Enter n to get all odd number until n : ");
scanf("%d", &n);
fclose(fptr);
return 0;
}*/
//2 number a & b are written in a file. write a program to replace them with
their sum.
/*int main(){
FILE *fptr;
fptr = fopen("Sum.txt", "r");
int a;
fscanf(fptr, "%d", &a);
int b;
fscanf(fptr, "%d", &b);
fclose(fptr);