This document contains an assignment submission for a programming fundamentals course. It includes 8 sections with 2 code examples each demonstrating different programming concepts like printing text, if/else statements, loops, functions, and arrays in C programming language. The codes show basics like finding the sum of two numbers, checking even/odd, generating patterns, finding repeated elements in an array. The assignment was submitted by Zohaib Zeeshan to their professor for the first semester course.
A few Programs, that are tested with compilers of respective IDEs s Bloodshed-DevC++, Visual Studio 2008, Qt 4.2. These are running successfully within console window of windows platform. So just enjoy coding. Programs in C of College days.
Structure Computer Programming with C-02 by Alamgir Hossain
Topics Covered: Introduction of a C program with Proper Exam. From this slide you will learn all about a c program.
Ex.1 Write a program to print the following pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ex.2 Write a program to find bigger of three integers.
Ex.3 Write a program to calculate GCD between two numbers.
Ex.4 Write a program to find transpose of matrix.
Ex.5 Write a program which deletes an element from an array & display all other elements.
Ex.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3.
Ex.7 Write a program to calculate the total amount of money in the piggy bank, given that coins of Rs.10, Rs.5, Rs.2, RS.1.
& many more.....
A few Programs, that are tested with compilers of respective IDEs s Bloodshed-DevC++, Visual Studio 2008, Qt 4.2. These are running successfully within console window of windows platform. So just enjoy coding. Programs in C of College days.
Structure Computer Programming with C-02 by Alamgir Hossain
Topics Covered: Introduction of a C program with Proper Exam. From this slide you will learn all about a c program.
Ex.1 Write a program to print the following pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ex.2 Write a program to find bigger of three integers.
Ex.3 Write a program to calculate GCD between two numbers.
Ex.4 Write a program to find transpose of matrix.
Ex.5 Write a program which deletes an element from an array & display all other elements.
Ex.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3.
Ex.7 Write a program to calculate the total amount of money in the piggy bank, given that coins of Rs.10, Rs.5, Rs.2, RS.1.
& many more.....
These problems are so common that you will find in any C learning curriculum. Either in your college or in any IT institute.
I have provided solutions to these problems as well.
Happy learning...
In C Programming create a program that converts a number from decimal.docxtristans3
In C Programming create a program that converts a number from decimal to binary. You must use a stack to complete this assignment. • Void pop() • Void push(int data) • Int top() • Int isEmpty() You must create an implementation of a stack. You may use either an array or a linked list as the underlying structure. You will, at a minimum, need to implement the following stack functions: Your program should take decimal input from the user, and convert it to binary, and simply print it out.
Solution
normal program
#include<stdio.h>
int main(){
long int decimalNumber,remainder,quotient;
int binaryNumber[100],i=1,j;
printf(\"Enter any decimal number: \");
scanf(\"%ld\",&decimalNumber);
quotient = decimalNumber;
while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
}
printf(\"Equivalent binary value of decimal number %d: \",decimalNumber);
for(j = i -1 ;j> 0;j--)
printf(\"%d\",binaryNumber[j]);
return 0;
}
using stack
.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
1. 1
Assignment #4
Subject: Programming Fundamentals
Semester: 1st
Submitted To: Sir. Junaid
Submitted By: Zohaib Zeeshan
Roll No: BSSE-F17-57
Date: 22/01/2018
Department of CS&IT
(BSSE)
University Of Sargodha Mandi Bahauddin Campus
2. 2
Programming Fundamentals
(1). Printing text on screen:
a). Write a simple C program.
Code:
#include<stdio.h>
int main(void)
{
printf(“Welcome to C!”);
return 0;
}
Output:
b). Write a program to find sum of two integers.
Code:
#include<stdio.h>
int main()
{
int a=5;
int b=7;
int sum;
sum = a+b;
printf("The sum is = %d", sum);
}
Output:
(2). Write two code examples of if-else.
a). Find maximum between two numbers.
Code:
#include<stdio.h>
int main()
{
int num1, num2;
printf("Enter two integers to find which is maximumn");
scanf("%d%d", &num1, &num2);
if(num1 > num2){
printf("First numbers is maximumn");
}
else
{
printf("Second is maximumn");
}
return 0;
}
3. 3
Output:
b). Write a program to check an integer is evenor odd.
Code:
#include<stdio.h>
int main()
{
int num;
printf("Enter an integer to check even or oddn");
scanf("%d", &num);
if(num % 2 == 0)
{
printf("Evenn");
}
else
{
printf("Oddn");
}
}
Output:
(3). Write two code examples of switch statement.
a). Write a code to check an alphabet is vowel or consonant.
Code:
#include<stdio.h>
int main ()
{
char ch;
printf("Enter an alphabetn");
scanf("%c", &ch);
switch (ch)
{
case'a':
printf("a is voweln");
break;
case 'e':
printf("e is voweln");
break;
4. 4
case 'i':
printf("i is voweln");
break;
case 'o':
printf("o is voweln");
break;
case 'u':
printf("u is woweln");
break;
case 'A':
printf("A is voweln");
break;
case 'E':
printf("E is voweln");
break;
case 'I':
printf("I is voweln");
break;
case 'O':
printf("O is voweln");
break;
case 'U':
printf("U is voweln");
break;
default:
printf("is consonant");
}
return 0;
}
Output:
b). Write a code to check number is evenor odd.
Code:
#include<stdio.h>
int main()
{
int num;
printf("Enter a number to check even or oddn");
scanf("%d", &num);
switch(num % 2){
5. 5
case 0:
printf("Number is Evenn");
break;
case 1:
printf("Number is Oddn");
break;
}
}
Output:
(4). Write two code examples of For Loop.
a). C program to find power ofa number using for loop.
Code:
#include<stdio.h>
int main(){
int base,exponent;
int power = 1;
int i;
printf("Enter base: n");
scanf("%d", &base);
printf("Enter exponenet: n");
scanf("%d", &exponent);
for(i=1; i<=exponent; i++){
power=power*base;
}
printf("%d ^ %d = %d", base, exponent, power);
return 0;
}
Output:
b). C program to print all even numbers from 1 to n.
Code:
#include<stdio.h>
int main(){
int i,n;
printf("Print all even numbers: n");
scanf("%d", &n);
printf("Even numbers from 1 to %d are n", n);
6. 6
for(i=1; i<=n; i++){
if(i%2 == 0){
printf("%d ", i);
}
}
return 0;
}
Output:
(5). Write two code examples using while loop.
a). C program to print multiplication table ofa number using while loop.
Code:
#include <stdio.h>
int main()
{
int i, num;
printf("Enter number to print table: ");
scanf("%d", &num);
while(i <=10)
{
printf("%d * %d = %dn", num, i, (num*i));
i++;
}
return 0;
}
Output:
b). Write a program to genrate star pattern as shown below using while loop.
Code:
#include<stdio.h>
int main()
{
int i,j;
8. 8
i++;
}
while(i<=10);
return 0;
}
Output:
(7). Write two code examples of Functions.
a). C program to find cube ofa number using function.
Code:
#include <stdio.h>
/* Function declaration */
int cube(int num);
int main(){
int num;
int c;
printf("Enter any number: ");
scanf("%d", &num);
c = cube(num);
printf("Cube of %d is %d", num, c);
return 0;
}
int cube(int num)
{
return (num * num * num);
}
Output:
b). Find factorial of a number using function.
Code:
#include<stdio.h>
int factorial(int);
int main(){
int fact;
int numbr;
printf("Enter a number: ");
scanf("%d",&numbr);
9. 9
fact= factorial(numbr);
printf("Factorial of %d is: %d",numbr,fact);
return 0;
}
int factorial(int n){
int i;
int factorial;
factorial =1;
for(i=1;i<=n;i++)
factorial=factorial*i;
return(factorial);
}
Output:
(8). Write two code examples of Array.
a). Write a program to find repeated elements using array.
Code:
#include<stdio.h>
int main(){
int i,arr[20],j,num;
printf("Enter size of array: ");
scanf("%d",&num);
printf("Enter any %d elements in array: ",num);
for(i=0;i<num;i++)
{
scanf("%d",&arr[i]);
}
printf("Repeated elements are: n");
for(i=0; i<num; i++)
{
for(j=i+1;j<num;j++)
{
if(arr[i]==arr[j])
{
printf("%dn",arr[i]);
}
}
}
return 0;
}
Output:
10. 10
b). Find largest element using array.
Code:
#include <stdio.h>
int main()
{
int array[50], size, i, largest;
printf("Enter the size of the array: n");
scanf("%d", &size);
printf("Enter %d elements of the array: n", size);
for(i=0; i<size; i++){
scanf("%d", &array[i]);}
largest = array[0];
for (i = 1; i < size; i++)
{
if (largest < array[i])
largest = array[i];
}
printf("The largest element is : %dn", largest);
return 0;
}
Output: